Question
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
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
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