This code works fine if I enter something that isn't a number in, e.g. F
: it will print the error message. However, if I enter e.g. 2F2
or , it will take the 2
and pass the check, continue in my code and on the next cin >>
statement it will put the F
in, and then it loops back and puts the 2
in.
How do I make it so it only accepts a single number e.g. 2
and not e.g. 2F2
or 2.2
?
int bet = 0;
// User input for bet
cout << " Place your bet: ";
cin >> bet;
cout <<
// Check if the bet is a number
if (!cin.good())
{
cin.clear();
cin.ignore();
cout << endl << "Please enter a valid number" << endl;
return;
}