我正在用 C++ 创建一个井字游戏程序并且几乎完成了它,我遇到的问题是游戏何时需要以平局结束。我创建了一个 if-statement
来检查何时选择了特定组合,即使只满足一个条件,它也会发现它是真的。
这是代码...
//takes the users selections and sees if all spots are filled in without a match.
if((b1== "O" || "X") && (b2 == "O" || "X") && (b3 == "O" || "X")){
cout << "The game ended in a tie.";
// Flip = 3 ends the game in a tie.
flip = 3;
}
答案 0 :(得分:3)
条件:
b1== "O" || "X"
评估为:
(b1=="O") || "X"
这总是正确的。你可能想要:
(b1=="O" || b1=="X")