I’m trying to validate user input that user must enter number and it must be greater than 0, the validation of only numbers I got it working; however, I can’t seem to incorporate the validation of greater than 0
float income;
cout << "How much did you earn last year: ";
//validating imput for income
while(!(cin >> income))
{
char ch;
cin.clear();
cout << "Sorry, number must be biger than \"0\" \n"
<< "How much did you make last year: ";
while(cin.get(ch) && ch != '\n');
}
Just add the condition to the
while, and handle it in the loop: