Question: [In C++] How do you handle wrong input datatypes? My input was w or w w w w when it's supposed to be a single
[In C++] How do you handle wrong input datatypes? My input was "w" or "w w w w" when it's supposed to be a "single digit" integer input. I want it to be able to do error checking if a string or char is typed and ask again to type integers but instead I get an infinite loop. Here is my code: main(){
int a, b, c, d, sum = 0; cout << "Type your four digits in the format (1 2 3 4) " << endl; cin >> a >> b >> c >> d;
//Checking for single digits while((a > 10 || a < 0) || (b > 10 || b < 0) || (c > 10 || c < 0) || (d > 10 || d < 0)){
cout << "Incorrect input, use single digits only (0-9)" << endl; cin >> a >> b >> c >> d;
} }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
