I have this simple code for input validation where the only options are 1 and 2. But if the user entered a character, the loop becomes never-ending. How do i validate for incorrect input datatype?
Code:int input; while (input != 1 && input != 2) { cout << endl << "Invalid input! Try again: "; cin >> input; }