RealDavidLiu
2019-12-20 21:38
采纳率: 40%
浏览 480

请问如何解决如图“表达式必须是可修改的左值”的问题?

//二维数组应用:tic-tac-toe(井字棋)
/*#include<stdio.h>
int main()
{
    const int size = 3;
    int board[size][size];
    int i, j;
    int numofx;
    int numofo;
    int result = -1;//-1:没人赢,1:x赢,0:o赢
    for (i = 0; i < size; i++)
    {
        for (j = 0; j < size; j++)
        {
            scanf("%d", &board[i][j]);
        }
    }// 数组初始化(读入矩阵)
    for (i = 0; i < size && result == -1; i++)
    {
        numofo = numofx = 0;
        for (j = 0; j < size; j++)
        {
            if (board[i][j] == 1)
            {
                numofx++;
            }
            else
            {
                numofo++;
            }
        }
        if (numofo == size)
        {
            result = 0;
        }
        else if (numofx == size)
        {
            result = 1;
        }
    }//检查行
    if (result = -1)
    {
        for (j = 0; j < size && result = -1; j++)
        {
            numofo = numofx = 0;
            for (i = 0; i < size; i++)
            {
                if (board[i][j] == 1)
                {
                    numofx++;
                }
                else
                {
                    numofo++;
                }
            }
            if (numofo == size)
            {
                result = 0;
            }
            else if (numofx == size)
            {
                result = 1;
            }
        }
    }
    numofo = numofx = 0;
    for (i = 0; i < size; i++)
    {
        if (board[i][i] == 1)
        {
            numofx++;
        }
        else 
        {
            numofo++;
        }
    }
    if (numofo == size)
    {
        result = 0;
    }
    else if (numofx == size)
    {
        result = 1;
    }
    numofo = numofx = 0;
    for (i = 0; i < size; i++)
    {
        if (board[i][size - i - 1] == 1)
        {
            numofx++;
        }
        else
        {
            numofo++;
        }
    }//检查对角线
    return 0;
}
```![图片说明](https://img-ask.csdn.net/upload/201912/20/1576848981_633140.png)
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • threenewbee 2019-12-20 22:16
    已采纳

    result = -1
    ->
    result == -1

    问题解决的话,请点下采纳

    打赏 评论

相关推荐 更多相似问题