Is there any other way to the same thing goto does?(You know what i mean i'm just too lazy too explain it right now >.<)
Goto messes everything up >.
For example, let's say i made a game that displays a menu, like:

"1. Play where is waldo
2.Quit"

Then you choose to play "Where is Waldo".
When you find him the program says "You won! and transports you back to the menu using goto.
But the next time you try to play "Where is Waldo" it'll say "You won!" again.
How can i fix that?
I'd like really simple answers, cuz kinda new to C++ :S
And please make an example too.

Recommended Answers

All 9 Replies

My guess is that the program needs to reinitialize some variables. But you can almost always avoid using the goto statement at all

bool done = false;
int response;

while( !done )
{
     response = menu();
     if( response == 2
     {
         done = true;
     }
     else
     {
          // initialize game variables here and
          // play game
     }
}

Oh yeah!
Can someone just give me a quick explanation of what bool does?
I kinda understand the conept of it but i don't know how to use it :S
And i didn't quite understand your explanation :S

bool is a variable that only contains 0 (false) or 1 (true). You use it only when you want something to be either true or false. I could also have written the while statement like this: while( done == false)

commented: Thanks +1

bool is the boolean datatype. A variable declared as a bool can have 2 values true (= 1) or false (= 0).

Here is an explanation with an example.

bool is a variable that only contains 0 (false) or 1 (true). You use it only when you want something to be either true or false. I could also have written the while statement like this: while( done == false)

So kinda like:

bool test;
string input;

cout << "hi";
cin >> input;

if(input==hi)
 test = 0

else
 test = 1

if(test = 1)
 cout << "poop";

else
 cout << "wow";

Is that the main idea of how it works?

not ... exaaactly !!

bool is a datatype .. so you cannot do bool == smthing

I don't know what you're trying to do, but here are some modifications.

bool test;
string input;

cout << "hi";
cin >> input;

if(input==hi)
 test = true;
else
 test = false; 

if(test == true)
 cout << "poop";
else
 cout << "wow";

not ... exaaactly !!

bool is a datatype .. so you cannot do bool == smthing

I don't know what you're trying to do, but here are some modifications.

bool test;
string input;

cout << "hi";
cin >> input;

if(input==hi)
 test = true;
else
 test = false; 

if(test == true)
 cout << "poop";
else
 cout << "wow";

sorry, my bad :P

bool test;
string input;

cout << "hi";
cin >> input;

if(input=="hi")
 test = false;

else
 test = true;

if(test == true)
 cout << "poop\n";
else
 cout << "wow\n";

Alright thanks :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.