| View previous topic :: View next topic |
| Author |
Message |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Fri Jan 27, 2006 1:23 am Post subject: 3 simple c++ questions |
|
|
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: | | if (iField[x + 1][y] == BlockKind) || (iField[x + 1][y] == BlockKind + 2) { |
with this code:
| Code: | 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: | | 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...) _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
sandberg
Joined: 05 Oct 2005 Posts: 90 Location: Denmark
|
Posted: Fri Jan 27, 2006 1:43 am Post subject: |
|
|
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 |
|
| Back to top |
|
 |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Fri Jan 27, 2006 1:52 am Post subject: |
|
|
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 _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
sandberg
Joined: 05 Oct 2005 Posts: 90 Location: Denmark
|
Posted: Fri Jan 27, 2006 1:57 am Post subject: |
|
|
| 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 |
|
| Back to top |
|
 |
|