Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have to write a c++ program were it would ask for you to input a numerical value and the numerical value will be displayed

I have to write a c++ program were it would ask for you to input a numerical value and the numerical value will be displayed in the output. However the program should only allow numerical values so symbols, letters, and blank spaces should not be allowed. I am having problem when I input a value of 134abc the value inputed should not be allowed but it is, and also Im having trouble when I enter a blank value "just enter" it just ignores this input rather than displaying an error in the input. Also when you input the number 0 the program does not shutdown. REally need Help Thank You!

This is my code right now:

#include #include

using namespace std;

/* * */ int main() { cout << "Enter an int or (0) to exit: "; char space = ' '; int x; if (cin == space){ cout << "oops"; }

if (cin == 0){ cout << "Bye!!"; exit(0); } while(!(cin >> x)){ cin.clear(); cin.ignore(numeric_limits::max(), ' '); cout << "Invalid input. Try again: "; } cout <<"Display number:" << x; return 0; }

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

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

8th Edition

013460153X, 978-0134601533

More Books

Students also viewed these Databases questions

Question

7. Determine what feedback is provided to employees.

Answered: 1 week ago