Don't make fun of me because my question seems kind of juvenile to you...I started learning C++ maybe three days ago, so....
With that said, I'm having a problem with a "game" I'm trying to create where the object is to guess a number between 1 and 999. However, if one guesses wrong, the game is *supposed* to go back to the begenning and ask you to guess again. Here's the code.
As you can see, all the highlited places are where I want it to go. I thought about using the goto command, but from what I read (here, of course) I decided that the goto command was not what I wanted. If you could give me a hand, it would be much appreciated.Code:#include <iostream> #include <cstdlib> using namespace std; int a = rand()%999; int main() { int b; int a; int x = 1; cout<<"See if you can crack the code!"<<"\n"; cout<<"Guess #"<< x <<": "; cin>> b; cin.ignore(); x++; if (b>a) { cout<<"Too high, try again..."; int main(); //here } if (b<a) { cout<<"Too low, try again..."; int main(); //here } if (b == a) { int win(); //here } } int win(void) { char * y; cout<<"Correct!"; cout<<"Try to break another code?" "Y or N"; cin>> y; if (y == "Y") { int main(); //here } }



LinkBack URL
About LinkBacks


