Help validation

when i type 2342342344 it will print the message out "Hey! Only one integer (1 and 2), please:", but after that i type 123123132 or 3, i have to enter twice to retype the correct integer. How to solve the enter twice? (Sorry for bad English)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
int c;
  while (true)
			{
				cin >> c; // Grab the first character

				if (cin.get() != '\n' || c > 2 || c <= 0) // Look at the next character
				{
					cin.clear();
					cin.ignore(numeric_limits<streamsize>::max(), '\n'); // Clear the input stream
					cout << "Hey! Only one integer (1 and 2), please: ";
				}
				else
					break;
			}
Topic archived. No new replies allowed.