game help.

So I made a game and everything works just like I want it, but when the game finishes it just stops at the ending credits.It doesnt even close the program. I want the game to ask if it want to play again but it isn't working. any help?

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
  int main() {
	int choice;
	
		
		do
		{
			cout << "Welcome what would you like to do?" << endl
		<< "[1] Play the game" << endl
		<< "[2] Quit" << endl
		<< "Make your selection: ";
		cin >> choice;

		while (choice != 1 && choice != 2)
		{
			cout << endl;
			cout << "Sorry I did not get that. Please Select a 1 or 2 to continue... ";
			cin >> choice;
		}
			switch (choice)
			{
			case 1:
				start();
				gameplay(word);
				break;
			case 2:
				cout << "Goodbye." << endl;
				break;
			
			}
		} 
		while (choice != 2);
	    return 0;

	}
That code snippet seems to work. At what point it doesn't do what you want it to do?
Everything runs but either when you lose the game or win it jus say sorry you lose or yaa you won and doesnt go back to the menu. it should have completed case 1 and looped to show the menu again
Hi,

Try this, it's a lot simpler - no nasty choice != 1 && choice != 2 statements

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
bool Quit = false;

while (!Quit) {

menu();  // show the menu

switch (choice)
			{
			case 1:
				start();
				gameplay(word);
				break;
			case 2:
				cout << "Goodbye." << endl;
                                Quit = true;
				break;
			default:  // always have this - it catches bad input
                                cout << "Invalid option try again\n";
                                break;
			}
}
That is nicer thank you. I think I solved it. I rewrote some code and its finally doing what I want.
Topic archived. No new replies allowed.