I'm trying to print an error message if the user does not enter anything into the input prompt, and if what they enter is zero or less.
void checkScoreInputed(int* qaltScores, int i){
while(true){
// cin.clear(); here?
if ((cin >> qaltScores[i]) && (qaltScores > 0)){
// also tried placing cin.clear() here.
break;} else // else is optional
cout << "Please supply a positive number for the score: ";
}
}
I've tried placing cin.ignore() and cin.clear() both before and after the if statement, but I am still getting an infinite loop of cout << "Please supply...."
after the user enters a non-integer value, like a character. How can I fix this?