I wrote a function which shall only proceed if an int
is input. If the cin
fails, it shall do the do{...} while()
once again until an int
is input, not a char
.
My problem is, once I input a char
, it ends up in an infinite loop. I can't tell why.
int syst ()
{
int basisSys;
bool opAga = false;
do
{
cout << "Type the base you wanna calc. in" << endl;
cin >> basisSys;
if (cin.fail())
{
opAga = true;
}
}
while (opAga == true);
cout << endl << "You are calc. in " << basisSys << "system" << endl << endl;
return basisSys;
}