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:
How can this be prevented?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; }




Reply With Quote