i'm still in the beggining of learning C/C++, and i'm trying to figure out how to prevent certain inputs from the user in a simple program. I would like to know how to prevent inputs such as empty input, 1 123123
that would make instruction variable = 1, but i wanted the program to give an error.
#include <iostream>
#include <limits>
using namespace std;
int instruction() {
int instruction;
cout << "Do you want to see the tutorial of the game? If yes press: 1, else press: 0" << endl << "--> ";
while (!(cin >> instruction) || (instruction != 1 && instruction != 0)){
cout <<"Error: Must introduce 1 or 0" << endl << "--> ";
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(),'\n');
}
cout << instruction;
return 0;
}