Need help validation int

No matter i put the validation it will infinite loop when type word. Pls help

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
do{
else if (choice == 5)
		{
			system("cls");
			int c, c1;

			cout << "Where do you want to display the output. (1 - File / 2 - Screen)" << endl;
			cin >> c;
			while (!cin)
			{
				cin.clear();
				cout << "Please, enter only an INTEGER> " << flush;
				cin >> c;
				break;
			}
		
			cout << "Do you want to display book list for every student. (1 - YES / 2 - NO)" << endl;
			cin >> c1;
			while (!cin)
			{
				cin.clear();
				cout << "Please, enter only an INTEGER> " << flush;
				cin >> c1;
				break;
			}

			Display(list, c, c1);
			break;
		
		}
}while (true);

You do clear the stream errors, but the characters of the word are still in the stream. Formatted integer input does not consume the offending characters.

See cin.ignore
Thx for the reply, now i have solve it.
Topic archived. No new replies allowed.