atoi typically returns 0 on failure, so if you check the string for 0, and it's FALSE, then that mean it's an invalid number.
But, oh crap, I was going to suggest that >_< Oh well.
Printable View
atoi typically returns 0 on failure, so if you check the string for 0, and it's FALSE, then that mean it's an invalid number.
But, oh crap, I was going to suggest that >_< Oh well.
That's why I said check the input for 0.
Code:char buf[10];
cout << "Enter number: ";
cin >> buf;
if (atoi(buf) == 0 && buf[0] != '0'); // User did not enter 0, so it's not a number
if (atoi(buf) == 0 && buf[0] == '0'); // User actually did input 0.