在得到第二個if語句並獲取新的char值之後,int數似乎不會被替換。任何提示,我可以如何改變這個如此之後如果語句的char值回到int數?如果語句問題
if (c < '9' || c > '0')
{
int number = c - '0';
if (board[number - 1] == 'X' || board[number - 1] == 'O')
{
cout << "Please enter another Number";
cin.get(c);
cin.ignore(numeric_limits<int>::max(), '\n');
}
if (board[number - 1] != 'X' || board[number - 1] != 'O')
{
if (player == 'X')
{
player = 'O';
}
else
{
player = 'X';
}
cout << "player " << player << " your number is " << number << endl;
// Your implementation here...
board[number - 1] = player;
}
}
這種情況持續發生:
1 | 2 | 3
4 | 5 | 6
7 | 8 | 9
Please Enter Box Number: 1
player X your number is 1
X | 2 | 3
4 | 5 | 6
7 | 8 | 9
Please Enter Box Number: 1
Please enter another Number2
player O your number is 1
O | 2 | 3
4 | 5 | 6
7 | 8 | 9
Please Enter Box Number:
板[ - 1] =「X! '|| board [number - 1]!='O'當它被填充時不是錯誤的嗎? – user868756
board [number - 1]不能同時爲'X'和'O'。它總是不等於至少一個或另一個。 「||」意思是OR,當然,如果OR的任一邊是TRUE(因爲它不相等),整體表達式就是TRUE。一方或另一方將始終爲真。 –
@ user868756:即,OR('||')是_inclusive_,不是唯一的。 – ildjarn