infinite output loop if non integer entered. :(

cant for the life of me think of why my validation goes in to an infinite output loop when non integers are entered.


part of my main function:
1
2
3
4
 do {
                cout << endl << endl << "Enter the number of days in the month (between 27 and 37): ";
                cin >> numDays;
        } while (isNotValidNum(numDays));


this is the called function:
1
2
3
4
5
6
7
8
9
bool isNotValidNum(int daynum) {
                if ((daynum < 27) || (daynum > 37)) {
                        cout << endl <<"Number-of-days value out of range, please try again.";
                        return true;
                }
                else {
                        return false;
                }//end else
}//end isValidDay 


When a non-integer is entered, the fail flag is set for the cin stream, and the invalid input remains in the stream.
See this thread for example of how to fix http://www.cplusplus.com/forum/beginner/87178/#msg467738
Topic archived. No new replies allowed.