For my program I pose a question, "Would you like to play a game?," before the program presents the menu options of the types of games to play. I am trying to add error handling to the yes or no question. I suppose that my overall problem/question is how do you clear a cin>> to re-input the menu data to go on to the next step of the game options? Any feedback is welcomed!
//User Chooses To Play Or Not To Play
cout << "Would You Like To Play A Game? (Y/N): " << endl;
cin >> playGame;
playGame = (toupper(playGame));
if (playGame == 'Y')
{
cout << "Fantastic! What Would You Like To Play Today?\n P for PIG\n B for BLACKJACK\n\n E to EXIT\n" << endl;
cin >> gameChoice;
gameChoice = (toupper(gameChoice));
}
if (playGame == 'N')
{
cout << "We Can Play Another Day... Goodbye!" << endl;
system("pause");
return 0;
}
if (playGame != 'Y' && playGame != 'N')
{
cout << "USER INPUT ERROR. . . Please Re-Enter Answer: ";
cin.ignore();
cin >> playGame;
playGame = (toupper(playGame));
}