How to restart ur script/program ?

Alright so I have this program I am making. Started it just to kinda refresh some things I kinda already knew, as well as try to learn some new stuff. I started this program with no given direction and just kinda went with it.

I guess you could say I started it as a hang man game, but then I realized I dont know how to set a string to have a random value out of the English dictionary. So I just made a mock program to pratice if statements to check stuff.

http://pastebin.com/m470b4005 <---- my code so far

Now keep in mind I have only been at C++ for about 3 - 4 days now, I know the code might be sloppy, and not proper.

THE QUESTION: When the user chooses "Y" to continue, I would like the program to start over from I guess step 1 (which is entering ur name, guess thats not a good idea, but its a start). Thx guys!
This kind of thing is typically done in a do/while loop:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
int main(int argc,char* argv[])
{
  bool keepplaying = true;

  GetPlayerName();
  do
  {
    GenerateRandomWord();
    DoOtherHangmanStuff();
    keepplaying = DoesUserWantToPlayAgain();
  }while(keepplaying);

  return 0;
}
Last edited on
hmmmm...
You could initialize all of the variables and then go into a do while loop with this at the end of the loop
1
2
3
cout << "Do you want to continue? (y/n) ";
cin >> somechar;
}while( (somechar == 'y') || (somechar == 'Y') );
You can also use an infinite loop and a break statement:
1
2
3
4
5
6
7
while(true)
{
    //Do something
    if ( You_Want_To_Stop ) break;
    if ( You_Want_To_Restart ) continue;
    //Do something else
}
Topic archived. No new replies allowed.