Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

[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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Filing And Computer Database Projects

Authors: Jeffrey Stewart

2nd Edition

007822781X, 9780078227813

More Books

Students also viewed these Databases questions

Question

What is DDL?

Answered: 1 week ago