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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started