Wrong input handling with cin
I am trying to write code that will accept user input, and any non-integer value will return an error message followed by a prompt to re-enter.
My current method of doing this works fine if a user enters characters, however if the user enters a float my program becomes confused.
Whats the best way to do this?
Here's my code:
Thanks a bunch!
cout << "\nEnter steps per turn\n\n> ";
if (((cin >> spt)==0)) //Input and error handling
cout << "\nOnly positive integers please!\n";