Public Group

# this... is a retarded error [help]

This topic is 3926 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

void change() { bool b = true; if(black == 0 && b) { black = 1; b = false; } if(black == 1 && b) { black = 0; b = false; } } so... why doesnt that work? any lang that isnt super retard would easely get this right, but c++ says "OHHHHH black IS ALWAYS 0 LOL" i think this is really retard, and have been working on fixing it for 2 hours. everything i do at this is right, but c++ is doing something retarded that i cant see. i already know that the function is triggering, and that the bug is in this function, so would someone please help?

##### Share on other sites
Moving to For Beginners.

##### Share on other sites
Quote:
 Original post by Robo-Linkso... why doesnt that work?

What does it do? What do you expect it to do?

##### Share on other sites
0) Only a poor workman blames his tools. In the future, take a walk, a deep breath, and calm down before you come and post. You're letting your frustration control you, causing you to place the blame on the compiler (I assume this what you mean when you personify C++), which doesn't make you look good.

1) You haven't provided enough information. Post the actual error the compiler is giving you, in full, and the actual source code that you're using -- not a snippet you think is relevant, because (as you don't know what the problem is), you're in no position to judge what is an is not relevant.

The problem the code that you've presented is that "black" is an unknown identifier, which will cause a compiler error. Presumably your real code includes a definition and initialization of "black" somewhere, and you need to show that.

##### Share on other sites
what i want it to do
if(black == 0)
black = 1;

else if(black == 1)
black = 0;

if you run this it changes black from 0 to 1 or 1 to 0
no matter what i put it runs both though.

and i've even tried making it return int and return 0 after it changes it once.

also @Mod
wasnt it already in For Beginners? o.O;

##### Share on other sites
I think it's supposed to "flip" the value of black, of course there is an easier way.

void change(){   if( black )   {      black = 0;   }   else   {      black = 1;   }}

or even just replace the whole function with:

black = black ? 0 : 1;

Edit:

Quote:
 if(black == 0)black = 1;else if(black == 1)black = 0;

Why didn't you just do that? The OP made it seem like you didn't know the else statment, what the hell is the point of the variable "b" then?

##### Share on other sites
Quote:
 Original post by jpetrie0) Only a poor workman blames his tools. In the future, take a walk, a deep breath, and calm down before you come and post. You're letting your frustration control you, causing you to place the blame on the compiler (I assume this what you mean when you personify C++), which doesn't make you look good.1) You haven't provided enough information. Post the actual error the compiler is giving you, in full, and the actual source code that you're using -- not a snippet you think is relevant, because (as you don't know what the problem is), you're in no position to judge what is an is not relevant.The problem the code that you've presented is that "black" is an unknown identifier, which will cause a compiler error. Presumably your real code includes a definition and initialization of "black" somewhere, and you need to show that.

2) this is a closed source project, so i cant do that. and its not a compile error, its a logical one.

3) yea, black is an Int set to 0.

basicly you could just say the rest of the code is
int main()
{
int black = 0;
change();
cout << black;
change();
cout << black;
return 0;
}

##### Share on other sites
If, as it sounds, this is a boolean variable to gate whose turn it is, or which color the player is (in chess or othello, for example), and even more concise solution is
// Assumingbool black = true;// Thenvoid change(){  black = !black;}

If you really want to be pointless secretive about your code, go write a mock program that exhibits the same unexpected behavior and post that.

And no, it was posted in Game Programming originally.

##### Share on other sites
Quote:
Original post by Scet
I think it's supposed to "flip" the value of black, of course there is an easier way.

void change(){   if( black )   {      black = 0;   }   else   {      black = 1;   }}

or even just replace the whole function with:

black = black ? 0 : 1;

Edit:

Quote:
 if(black == 0)black = 1;else if(black == 1)black = 0;

Why didn't you just do that? The OP made it seem like you didn't know the else statment, what the hell is the point of the variable "b" then?

cause

Quote:
 if(black == 0)black = 1;else if(black == 1)black = 0;

doesnt work >.<

nor does
black = black ? 0 : 1;

-.-|||

##### Share on other sites
Quote:
 Original post by Robo-Linkdoesnt work >.<

because?

Quote:
 Original post by jpetrie1) You haven't provided enough information. Post the actual error the compiler is giving you, in full

• 34
• 12
• 10
• 9
• 9
• ### Forum Statistics

• Total Topics
631355
• Total Posts
2999512
×