Thanks for the help but still not following.
I tried this in the code:
Code:
while ( userSelection < 1 || userSelection > 4 )
{
if(cin.fail())
{
cin.ignore();
cout << "Please enter a number: ";
cin >> userSelection;
}
cout << "Please try again: ";
cin >> userSelection;
}
No good either. Still goes into the loop when entering a letter. Just runs a loop, Please enter a number. Please try again. Please enter a number. Please try again. Please enter a number. Please try again. Please enter a number. Please try again...
I could do with knowing WHY it fails. What's the problem with anything other than a number?
**update**
After doing a bit more digging, I found a snippet from another stackoverflow post and modified thus:
Code:
while ( userSelection < 1 || userSelection > 4 )
{
if (!(cin))
{
cout << "Please enter numbers only.\n";
cin.clear();
cin.ignore();
}
cout << "Please try again: ";
This works
However, should this line:
be
Code:
if(!(cin >> userSelection))
or does it not matter?
Sam.