[Resolved] Input valid data?
How can you prevent errors from occuring when a user inputs wrong information? Lets say I ask for an integer value (like below) and they put 'a'? It then causes a major spaz in the program.
Example Code:
Code:
#include <iostream>
using namespace std;
int main() {
int num;
cout << "Enter an Integer: ";
cin >> num;
while (num < 1 || num > 5) {
system("CLS");
cout << "Enter an INTEGER: ";
cin >> num;
}
cout << endl << num << endl << endl;
return 0;
}
How can this be prevented?