Hello all,
Can someone tell me how to check what a user entered is actually a number and not a character ?
Thanks in advance.
Hello all,
Can someone tell me how to check what a user entered is actually a number and not a character ?
Thanks in advance.
Look up the isdigit() function in the help. There are other ways too, but try that first.
Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.
If x is an integer, (cin >> x) evaluates to false if the input is non-numeric. Example:
[code]
int x;
cout << "Enter a number: ";
if(cin >> x)
{
cout << "You just input the number " << x << endl;
}
else
{
cout << "You didn't enter a proper number.\n";
}