Menu Error Checking

I have the following
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 bool Exit = false;
    
	while (!Exit)
	{
		int choice;
        
		cout << endl;
        cout << "=======================================" << endl;
        cout << "                                       " << endl;
        cout << " WELCOME TO STUDENT RECORD             " << endl;
		cout << "                                       " << endl;
        cout << "=======================================" << endl;
		cout << "Select Action: " << endl;
		cout << "1) Display Student Deails" << endl;
		cout << "2) Sort Using Insertion Sort" << endl;
		cout << "3) Sort Using Merge Sort" << endl;
		cout << "4) Search Sorted Array Using Binary Search" << endl;
		cout << "5) Add the Array to a Stack" << endl;
		cout << "6) Display the Array" << endl;
		cout << "7) Exit" <<endl;
		cout << "=======================================" << endl;
		cout << "Enter choice: ";
		cin >> choice;


if i enter a number it just sends me back to Menu. but if i enter a letter the Program goes into a Loop. how can i get a Error catch for this ?
1
2
3
4
5
6
if( cin>>choice ) //do stuff...
else{
   //input could not be interpreted as a number
   cin.clear();
   cin.ignore( numeric_limits<streamsize>::max() /*this is basically a big number*/, '\n' );
}
Topic archived. No new replies allowed.