C++ c+中输入验证的逻辑错误+;

C++ c+中输入验证的逻辑错误+;,c++,validation,C++,Validation,以下代码包含一个逻辑错误 每次我运行它并输入1或0代码时 在while循环中仍然执行。 有人能告诉我为什么吗 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()) {

以下代码包含一个逻辑错误 每次我运行它并输入1或0代码时 在while循环中仍然执行。 有人能告诉我为什么吗

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;
}
bool getmove()
{
布尔移动;
不能移动;
while(move!=1 | | move!=0 | |!cin.good())
{
如果(!cin.good())
{
不能移动;
}
其他的
{
不能移动;
}
}
回击动作;
}
看这一行:

while(move != 1 || move != 0 || !cin.good())
move!=1 | |移动!=0
(因为它不能两者都是)


此外,通过读入字符串之类的内容并对其进行测试,而不是依赖强制转换,可以避免一些麻烦。

如果您试图编写一个可以验证布尔值输入的函数,您的代码可以简化为:

bool getmove()
{
布尔移动;
无法>移动)
{

cout>move))
将重复循环,直到可以从控制台读取有效的布尔值并将其写入
move

非常感谢您,我不知道我怎么会错过它。我可以做:while((move!=1&&move!=0)| | | cin.很好)