Hey guys, ive just started learnng c++ after a year or so of java, one issue that has just cropped up for me is repeating input from console.
if for example i ask for an input, expecting just 1, and the user inputs 2 with a space inbetween how do i get it to ignore the second part?
e.g.#
"Guess the number im thinking of."
-> 4 5
"4 is the wrong number"
"Guess again"
"5 is the wrong number"
for(;;)
{
cin >> value;
if(value > 0 && value < 1000)
{
break;
}
else
{
cout << "Invalid entry. Please try again.\n";
}
}
If someone inputs an int, this will work fine, looping until a number between 1 and 999 is put in.... if you input a character e.g. K. it will spam "Invalid entry. Please try again"
I was hoping there would be a way to cancel all incoming consol inputs which would, as im asuming that when someone types in a character it in someway spams the console with commands.