3 simple c++ questions

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Ghoti
Posts: 288
Joined: Sat Dec 31, 2005 11:06 pm

3 simple c++ questions

Post by Ghoti »

Hi folks, i have two question which bother me for a while now and i have always worked around it but it is time to solve the stupid questions:

1.) how do i declare a boolean? bool gives errors in the compiler

2.) what is wrong with this:

Code: Select all

if (iField[x + 1][y] == BlockKind) || (iField[x + 1][y] == BlockKind + 2) {
with this code:

Code: Select all

main.c: In function 'CheckSurroundingField':
main.c:110: error: syntax error before '||' token
i want to just look if one of the tow i right and the execute the code

3) what is wrong with this:

Code: Select all

int CheckSurroundingField(int x, int y, int BlockKind){
the compiler says i didn't declare the x and y and BlockKind but these are the values i pass through how do i do this?

greets ghoti (a former visual basic programmer...)
sandberg
Posts: 90
Joined: Wed Oct 05, 2005 1:25 am
Location: Denmark

Post by sandberg »

Hi,

You declare a boolean as

bool some_var_name;

Just to make sure, that this is a C++ feature, it does not work in C.

About the last two questions, could you post the complete function instead. It might very well be something else than the two lines posted, that is the rootcause for the problem.
Br, Sandberg
Ghoti
Posts: 288
Joined: Sat Dec 31, 2005 11:06 pm

Post by Ghoti »

Okay i know use integers to do the same a boolean in my psp app so i'll stick with that.

I have corrected the last two they belonged together because when i solved the first i didn't get any error anymore like the 3th question so that is solved.

solving was removing the )(. i didn't know that i couldn't be done like i did:

if (x==a || x==b) {}

but not this:

if (x==a) || (x==b) {}

thank you for the answer
sandberg
Posts: 90
Joined: Wed Oct 05, 2005 1:25 am
Location: Denmark

Post by sandberg »

Ghoti wrote: solving was removing the )(. i didn't know that i couldn't be done like i did:

if (x==a || x==b) {}

but not this:

if (x==a) || (x==b) {}

thank you for the answer
Damn, I should have seen that :)

You need to have outer () on the expression. like below

if ((x==a) || (x==b)) {}

That'll work ..
Br, Sandberg
Post Reply