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:
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
}
elseif (choice2 == "n" || choice2 == "N")
{
return 0;
}
}
//if O wins
elseif (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
}
elseif (choice2 == "N" || choice2 == "n")
{
return 0;
}
}
//if players tie
elseif (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
}
elseif (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.