QUOTE(Unknown Hero @ 5 Sep, 2007 - 03:44 AM)

Try to declare qnum as char and then convert it to int.
Play with ASCII code a bit. 'A'...'Z' have ASCII code 65-90, and 'a'...'z' have ASCII code 97-122.
Numbers '0'...'9' have ASCII code 48-57.
That wouldn't work - if the user typed 99 when cin was looking for a char, cin would retrieve '9'.
A better solution would be to input a std::string using getline, and convert with a stringstream (This is generally better than clearing error flags on cin, and having to wipe out unwanted characters)
CODE
#include <iostream>
#include <sstream>
#include <string>
int main()
{
using namespace std;
string input;
cout << "Enter a number 1-99 inclusive: ";
getline( cin, input );
stringstream ss( input );
int n;
if( ss >> n )
{
cout << "You entered: " << n << endl;
}
else
{
cout << "Invalid input" << endl;
}
}
This post has been edited by Bench: 5 Sep, 2007 - 04:01 AM