新手,关于do while的问题,大家帮忙
#include int main(void)
{
int player = 0;
int winner = 0;
int row = 0;
int column =0;
int line = 0;
int choice = 0;
int i = 0;
char board[3][3] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'}
};
for(i=0;i<9 && winner == 0;i++)
{
printf("\n\n");
printf(" %c | %c | %c \n",board[0][0],board[0][1],board[0][2]);
printf("---+---+---\n");
printf(" %c | %c | %c \n",board[1][0],board[1][1],board[1][2]);
printf("---+---+---\n");
printf(" %c | %c | %c ",board[2][0],board[2][1],board[2][2]);
player = i%2 +1;
do
{
printf("\n\nPlayer %d enter the number of the square where you want to place %c: ",player,(player==1)?'x':'o');
scanf("%d",&choice);
row = --choice/3;
column = choice%3;
}
while(choice<1 || choice>9 || board[row][column]>'9'); /*这里不明白*/
board[row][column] = (player==1)?'x':'o';
if((board[0][0]==board[1][1] && board[0][0]==board[2][2]) || (board[0][2]==board[1][1] && board[0][2]==board[2][0]))
winner = player;
for(line=0;line<=2;line++)
{
if((board[line][0]==board[line][1] && board[line][0]==board[line][2])
|| (board[0][line]==board[1][line] && board[0][line]==board[2][line]))
winner = player;
}
printf("\n\n");
printf(" %c | %c | %c \n",board[0][0],board[0][1],board[0][2]);
printf("---+---+---\n");
printf(" %c | %c | %c \n",board[1][0],board[1][1],board[1][2]);
printf("---+---+---\n");
printf(" %c | %c | %c ",board[2][0],board[2][1],board[2][2]);
}
if(winner==0)
printf("\n你们都没赢,平局,握手言和");
if(winner==player)
printf("\n恭喜!! %d号选手赢了.",winner);
getchar();
getchar();
return 0;
}
问题在这里:
while(choice<1 || choice>9 || board[row][column]>'9');
如果我输入1,while 返回值应该是false,应该继续while下面的语句,而实际的结果是还要继续do的循环,为什么?