level 3
刚日坂川
楼主
有两段的,第一段画了三个格子,想把他们放一起然后报错。
不知道怎么弄就单独第二段,反复找,它一直对着“?”报错
大致如下:
//program 5.8 tic_tac_toe
#include <stdio.h>
int main(void)
{
int player = 0;//current player number -1 or 2
int winner = 0;// the winning player number
int choice = 0;
unsigned int row = 0;
unsigned int column = 0;
char board[3][3] = {//the board
{'1','2','3'},// initial values are charact'1'to'9'
{'4','5','6'},//used to select a vacant square
{'7','8','9'} //for a player's turn.
};
//the main game loop. the game continues for up to 9 turns
// as long as there is no winner
for (unsigned int i = 0;i < 9 && winner == 0;++i)
{
//display the board
player = i % 2 + 1;
//游戏循环和显示方格板
//program 5.8 tic -tac-toe 不可反复定义
// get valid play er square selection
do
{
printf("player %d , please enter a valid square number"
"for where you want to place your %c: ",
player, (player == 1) ? 'x' : 'o');
scanf(" %d", &choice);
row = --choice / 3;
column = choice % 3;
}while (choice < 0 || choice >8 || board[row][column] > '9');
//insert player symbol
board[row][column] = { player == 1 } ? 'x' : 'o';
}
return 0;
}
2022年11月06日 04点11分
1
不知道怎么弄就单独第二段,反复找,它一直对着“?”报错
大致如下:
//program 5.8 tic_tac_toe
#include <stdio.h>
int main(void)
{
int player = 0;//current player number -1 or 2
int winner = 0;// the winning player number
int choice = 0;
unsigned int row = 0;
unsigned int column = 0;
char board[3][3] = {//the board
{'1','2','3'},// initial values are charact'1'to'9'
{'4','5','6'},//used to select a vacant square
{'7','8','9'} //for a player's turn.
};
//the main game loop. the game continues for up to 9 turns
// as long as there is no winner
for (unsigned int i = 0;i < 9 && winner == 0;++i)
{
//display the board
player = i % 2 + 1;
//游戏循环和显示方格板
//program 5.8 tic -tac-toe 不可反复定义
// get valid play er square selection
do
{
printf("player %d , please enter a valid square number"
"for where you want to place your %c: ",
player, (player == 1) ? 'x' : 'o');
scanf(" %d", &choice);
row = --choice / 3;
column = choice % 3;
}while (choice < 0 || choice >8 || board[row][column] > '9');
//insert player symbol
board[row][column] = { player == 1 } ? 'x' : 'o';
}
return 0;
}
