| | |
Help with the goto thing.
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2008
Posts: 31
Reputation:
Solved Threads: 0
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++
And please make an example too.
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++

And please make an example too.
Last edited by tatainti55; Oct 17th, 2008 at 6:04 pm.
My guess is that the program needs to reinitialize some variables. But you can almost always avoid using the goto statement at all
C++ Syntax (Toggle Plain Text)
bool done = false; int response; while( !done ) { response = menu(); if( response == 2 { done = true; } else { // initialize game variables here and // play game } }
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
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) Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Oct 2007
Posts: 305
Reputation:
Solved Threads: 43
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.
Here is an explanation with an example.
•
•
Join Date: Oct 2008
Posts: 31
Reputation:
Solved Threads: 0
•
•
•
•
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)
C++ Syntax (Toggle Plain Text)
bool test; string input; cout << "hi"; cin >> input; if(input==hi) test = 0 else test = 1 if(test = 1) cout << "poop"; else cout << "wow";
Last edited by tatainti55; Oct 17th, 2008 at 6:47 pm.
•
•
Join Date: Oct 2007
Posts: 305
Reputation:
Solved Threads: 43
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 is a datatype .. so you cannot do bool == smthing
I don't know what you're trying to do, but here are some modifications.
C++ Syntax (Toggle Plain Text)
bool test; string input; cout << "hi"; cin >> input; if(input==hi) test = true; else test = false; if(test == true) cout << "poop"; else cout << "wow";
Last edited by stilllearning; Oct 17th, 2008 at 6:46 pm.
•
•
Join Date: Oct 2008
Posts: 31
Reputation:
Solved Threads: 0
•
•
•
•
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.
C++ Syntax (Toggle Plain Text)
bool test; string input; cout << "hi"; cin >> input; if(input==hi) test = true; else test = false; if(test == true) cout << "poop"; else cout << "wow";
C++ Syntax (Toggle Plain Text)
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";
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
![]() |
Similar Threads
- ambiguous part 3 (C)
- Deleting record from .dat file (C)
- Using VBA with Access (was: Please Help!!!) (Visual Basic 4 / 5 / 6)
- vBulletin mod_rewrite (PHP)
- Tricky Questions (C)
- have you ever abused ur powers? (Geeks' Lounge)
- New to PHP (PHP)
- need help with newly built computer (Windows NT / 2000 / XP)
- I Cant Install An Operating System! HELP! (Windows NT / 2000 / XP)
Other Threads in the C++ Forum
- Previous Thread: Unhandled Exception Error
- Next Thread: String Issue :(
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data database delete desktop developer directshow dll download dynamic encryption error file forms fstream function functions game generator getline givemetehcodez google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number output parameter pointer problem program programming project proxy python random read recursion recursive return string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






