Hi, I don't know exactly how to put it into words, but once my statement is met in one of my functions I am wanting it to move onto other functions and stop the current one until it is called for again, so far I have had no luck in doing this and am hoping someone else does.
Here is my code that I am struggling with:
void playAgain()
{
string choice2;
cout << "Would you like to Play again, y/n." << endl;
cout << "Enter here: ";
while (1)
{
cin >> choice2;
if (choice2 == "y" || choice2 == "Y")
{
system("cls");
resetGrid();
Display();
}
elseif (choice2 == "n" || choice2 == "N")
{
exit(0);
}
else
{
cout << "That is not the correct input, please try again." << endl;
playAgain();
}
}
}
I am not entirely sure whether the code is correct or not but to give you the run down so you can better understand I am wanting this function playAgain() to execute once a player has selected to play again at the end of the game, the first run of the game runs as normal but once this playAgain() function comes into it the game does not work as it should do, whilst entering the field numbers for the game it simply passes to the next lane and displays the playAgain() function which is not what I am wanting.
Here is also my main function if it helps:
You have some functions mentioned in your program (resetGrid(), Display() etc) whose definition does not appear in the code posted, so I could not replicate your results but in general what you're looking for is called a break statement - it is a statment that breaks the program out of a current loop (in your case an if loop) if certain conditions are met and the program then proceeds to execute the subsequent code. You can search on-line how to practice it in actual programs or post a small, self-contained program here