How to loop program back to start when finished?

solved:D
Last edited on
anyone?
Last edited on
Idea:
Make the code inside main() a function itself, and call it if the player chooses to play again

Here's what I'm saying might look like.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
void play();

     int main()
     {
          
          do{
               intro();          //Intro prints the intro  :D
               gameover(); //Gameover calls the play function if you choose to play
          }while( choice == 1 );

     }

void intro()
{
     //Print the intro
}

void play()
{
          do{

              //Code to play...

          }while( choice == yes );
}

void gameover()
{
     cout << "Would you like to play? ( 1 for yes, 2 for no )\n";
     cin >> choice; // you only need 1 int for making decisions, but do what   
                            // makes reading your code easier for yourself
     
     if( choice == "1" )
     {
          play();
     }
     else if(//gameover)
     {
          //... code
     }
}
Hey there, seriously thank you so much for the reply! I've been on this for song long and desperately needed it fixed
Thank you so much :)
Last edited on
Yeah, I'll give it a shot, but I've been working between mac and windows, so your code seems a little foreign to me (because I can't use anything strictly for one operating system)

When I'm finished ill post something.
Last edited on
Topic archived. No new replies allowed.