P
Pycco
I need the user to input an integer, and do some calculation with that
integer. Should the user input an invalid integer, I must return a
warning, saying it's an invalid input.
E.g.
int a;
cin >> a;
if (cin.fail())
cout << "Invalid input.";
else (...)
If the user inputs "four" instead of "4", it'll say "Invalid input".
But if the user inputs "4 + 0", the program won't enter in fail state,
and accept "4" as the value of "a", when it should say "Invalid
input."
What should I do in order to warn the user that "4 + 0" instead of "4"
is also an invalid input?
Thx!
integer. Should the user input an invalid integer, I must return a
warning, saying it's an invalid input.
E.g.
int a;
cin >> a;
if (cin.fail())
cout << "Invalid input.";
else (...)
If the user inputs "four" instead of "4", it'll say "Invalid input".
But if the user inputs "4 + 0", the program won't enter in fail state,
and accept "4" as the value of "a", when it should say "Invalid
input."
What should I do in order to warn the user that "4 + 0" instead of "4"
is also an invalid input?
Thx!