Answer to Question #5458 in C++ for zuhaib abbasi

Question #5458
write a program in c++ that tell you if your input is a number or if it is not and print it on screen.
1
Expert's answer
2011-12-08T09:13:57-0500
#include <iostream>
#include <limits>

using namespace std;

int main() {
& int number = 0;
& cout << "Enter an integer: ";
& cin >> number;
& cin.ignore(numeric_limits<int>::max(), '\n');

& if (!cin || cin.gcount() != 1)
cout << "Not a numeric value.";
& else
cout << "Your entered number: " << number;
& return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS