The following code contains a logical error
every time i run it and enter 1 or 0 the code
in the while loop is still executed.
can someone tell me why?
bool getmove()
{
bool move;
cout << "Would you like to make the first move?(1 for yes 0 for no)\n";
cin >> move;
while(move != 1 || move != 0 || !cin.good())
{
if(!cin.good())
{
cout << "ERROR please try again\n";
cin.clear();
cin.ignore(80,'\n');
cin >> move;
}
else
{
cout << "Invalid input please try again\n";
cin >> move;
}
}
return move;
}
Look at this line:
It will always be the case that
move != 1 || move != 0(because it can’t be both).Furthermore, you’ll avoid some trouble by reading in something like a string and testing that, rather than relying on casting.