So I'm writing a paper rock scissors program for class and I need to validate that the input is a number and not a letter, I get a infinite loop other wise. here is my function for it-
thanks!
Code:
int getHumanChoice()
{
int choice=0;
while(true)
{
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << "Please select your choice: " << endl;
cout << "Enter '1' for Rock" << endl;
cout << "Enter '2' for Paper" <<endl;
cout << "Enter '3' for Scissors" <<endl;
cout << "Enter '4' to Quit" << endl;
cout << endl;
cout << "What is your selection?: ";
cin >> choice;
cin.ignore(1000,10) ;
if (choice == 1 || choice == 2 || choice == 3 || choice == 4) break;
cout << "Invalid entry, please enter a number 1-4 " << endl;
}
thanks!