A
A_StClaire_
it's been frustrating rearranging these things in the code below and
never getting the result I want.
I'm looking for the system to cout a single "Invalid choice. Try
again:" in response to every incorrect entry the user gives, regardless
of whether the invalid entry is a single character or 20 characters.
can anyone help?
void Game::RunSinglePlayerGame()
{
bool quit = false;
while(quit == false)
{
RunSinglePlayerSequence();
Interface::Instance().ClearScreen();
int choice;
bool validChoice = false;
cout << "\n\n Play again?\n\n 1. Yes\n 2. No\n\n ";
while(validChoice == false)
{
cin >> choice;
switch(choice)
{
case 1:
validChoice = true;
break;
case 2:
validChoice = true;
quit = true;
cout << "\n\n\n\n Thanks for playing!\n\n ";
break;
default:
cout << "\n Invalid choice. Try again: ";
break;
}
}
}
}
never getting the result I want.
I'm looking for the system to cout a single "Invalid choice. Try
again:" in response to every incorrect entry the user gives, regardless
of whether the invalid entry is a single character or 20 characters.
can anyone help?
void Game::RunSinglePlayerGame()
{
bool quit = false;
while(quit == false)
{
RunSinglePlayerSequence();
Interface::Instance().ClearScreen();
int choice;
bool validChoice = false;
cout << "\n\n Play again?\n\n 1. Yes\n 2. No\n\n ";
while(validChoice == false)
{
cin >> choice;
switch(choice)
{
case 1:
validChoice = true;
break;
case 2:
validChoice = true;
quit = true;
cout << "\n\n\n\n Thanks for playing!\n\n ";
break;
default:
cout << "\n Invalid choice. Try again: ";
break;
}
}
}
}