Quantcast
Channel: CodeGuru Forums - Visual C++ Programming
Viewing all articles
Browse latest Browse all 3027

check if input is an integer

$
0
0
I have been trying to make a very simply programme that checks if the inputted information is an integer or not (i.e: that it contains no other characters).

I have tried using the isdigit function (but this only works for single characters)
i have tried cin.clear, cin.ignore (1000) but this doesn't work either..

can someone please suggest an effective way to check if x in the following programme has been entered correctly

#include <iostream>
using namespace std;

int main()
{
cout << "Please enter an integer (positive or negative)" << endl;
int x;
cin >> x;
HERE I WOULD LIKE CODE TO CHECK IF THE USERS INPUT IS VALID
}

thanks

Viewing all articles
Browse latest Browse all 3027

Latest Images

Trending Articles



Latest Images