I'm just starting to learn C++.. and this is really my first programming language, but I'm not sure how to prevent users from messing up my program when they start entering garbage. Here's an example I wrote:
Now lets say someone enters 'g'... it would just go into an infinite while loop.. and I'd have to close it. I've actually had this problem for quite a while. Any help is really appreciatedCode:#include <iostream> using namespace std; int main() { int choice; while (choice != 3) { cout << "Choice: "; cout << "\n(1) First\n(2) Second\n(3) Quit\n\n"; cin >> choice; if (choice == 1) { cout << "First\n"; } if (choice == 2) { cout << "Second\n"; } } cout << "Exit\n"; return 0; }