Solved: I have to write a c++ program were it would ask fo…

$30.00

Category:

Description

Solved: I have to write a c++ program were it would ask fo…

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 <limits>
#include <iostream>

using namespace std;

/*
*
*/
int main() {
cout << “Enter an int or (0) to exit: “;
char space = ‘\n’;
int x;
if (cin == space){
cout << “oops”;
}

if (cin == 0){
cout << “Bye!!”;
exit(0);
}
while(!(cin >> x)){
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), ‘\n’);
cout << “Invalid input. Try again: “;
}
cout <<“Display number:” << x;
return 0;
}


error: Content is protected !!