What's Here?
- Members: 149,632
- Replies: 506,753
- Topics: 79,851
- Snippets: 2,666
- Tutorials: 706
- Total Online: 2,116
- Members: 81
- Guests: 2,035
|
Code will check whether the number entered is integer or not.
|
Submitted By: Xing
|
|
Rating:
 
|
|
Views: 11,034 |
Language: C++
|
|
Last Modified: October 5, 2006 |
Snippet
#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;
}
Copy & Paste
|
|
|
Be Social
Reference Sheets
Bye Bye Ads
Monthly Drawing
Top Contributors
Top 10 Kudos This Month
|