So I'm taking a C++ class right now and we haven't gotten to strings yet but we've had to write programs that take user input, often as integers. But if the user puts in something that's not an int the program goes into an infinite loop. What's the proper way to read input?
Code:
int numRows;
do {
cout << "Enter an odd number between 1 and 19 : ";
cin >> numRows;
} while (numRows < 0 || numRows > 20 || !(numRows % 2) );