How to make a loop for 3 possible outcomes

I am wanting to have a loop which runs back to the beginning of the program if the player enters 'Y' to play again(I need it to go back to the Display() function which shows the game and clears any previous inputs prior to this as I am wanting to add in a scoring system later on), so far I have had no luck in accomplishing this and am hoping someone else knows, any help is much appreciated!
Here is my code involving the functions:

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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
int main()
{
		Menu();
		Names();
		b = 0;
		Display();
		//loop that will run until a player has won or tied
		while (1)
		{
			b++;
			Input();
			Display();
			//if player wins/tie function
			//if X wins
			if (Win() == 'X')
			{
				system("cls");
				cout << X << " has Won!" << endl;
				cout << "Would you like to Play again, y/n." << endl;
				string choice2;
				cin >> choice2;
				if (choice2 == "y" || choice2 == "Y")
				{
					//re-run program
				}
				else if (choice2 == "n" || choice2 == "N")
				{
					return 0;
				}
			}
			//if O wins
			else if (Win() == 'O')
			{
				system("cls");
				cout << O << " has Won!" << endl;
				cout << "Would you like to Play again, y/n." << endl;
				string choice2;
				cin >> choice2;
				if (choice2 == "y" || choice2 == "Y")
				{
					//re-run program
				}
				else if (choice2 == "N" || choice2 == "n")
				{
					return 0;
				}
			}
			//if players tie
			else if (Win() == '/' && b == 9)
			{
				system("cls");
				cout << "It's a Tie!" << endl;
				cout << "Would you like to Play again, y/n." << endl;
				string choice2;
				cin >> choice2;
				if (choice2 == "y" || choice2 == "Y")
				{
					//re-run program
				}
				else if (choice2 == "N" || choice2 == "n")
				{
					return 0;
				}
			}
			TogglePlayer();
		}
}


Every attempt I have made thus far of making a loop has made it so the choice to enter a position to place a symbol in pops up and when I enter anything the program basically crashes.
Last edited on
Topic archived. No new replies allowed.