if a program wants you to enter a number, if you were to happen to enter a letter is there any way to make the program say something like "hey you idiot i said number" THX!!
if a program wants you to enter a number, if you were to happen to enter a letter is there any way to make the program say something like "hey you idiot i said number" THX!!
One solution is isdigit().
Kuphryn
Another way might be string streams.
Or something similarCode:#include <iostream.h> int main() { int digit; cout << "Enter a number: "; cin >> digit; if(cin.fail()) { cin.clear(1); cin.ignore(80, '\n'); cout << "Hey you idiot! I said number." << endl; } return 0; }
I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P
I agree with Ronin.
Use If then or Switch statements. They are easy and hassle-free.