如何输出一个井字游戏表

How do I output a tic tac toe table?

本文关键字:游戏 一个 何输出 输出      更新时间:2023-10-16

这是我到目前为止的函数,但它没有产生正确的输出。任何帮助吗?

void Display(char gameBoard[][SIZE])
{
    int row, col;
    for (row = 0; row < SIZE; row++)
    {
        cout << "-----------" << endl;
        for (col = 0; col < SIZE; col++)
        {
            cout << gameBoard[row][col] << " |";
        }
    }

}

我猜这就是你真正想要的代码:

void Display(char gameBoard[][SIZE])
{
    int row, col;
    for (row = 0; row < SIZE; row++)
    {
        cout << "----------" << endl;
        cout << "|";
        for (col = 0; col < SIZE; col++)
        {
            cout << gameBoard[row][col] << " |";
        }
        cout << endl;
    }
    cout << "----------" << endl;
}
    cout << "/n/t" << " | " << "/n/t" << " | " << "/t";
    cout << "/n/t" << "----------------";

这可能有效。

希望这对你有帮助!这将是一个整洁的板!

#include <iostream>
#include <string>
using namespace std;
int main() {

    int SIZE = 3;
    int row, col;
    string gameBoard[3][3];
    //Initializing what gameBoard is -- I made it equal to 'X'
    for (row = 0; row < SIZE; row++)
    {
        for (col = 0; col < SIZE; col++)
        {
            gameBoard[row][col] = 'X';
        }
    }

    //Outputing the table 
    for (row = 0; row < SIZE; row++)
    {
        for (col = 0; col < SIZE; col++)
        {
            if (col == 0) {
                cout << gameBoard[row][col] << "  ";
            }
            else {
                cout << "  |   " << gameBoard[row][col];
            }
        }
        if (row != SIZE - 1) {
            cout << endl << "--------------------" << endl;
        }

    }
        cout << "n";
        return 0;
}

如果你有任何问题就问!

相关文章: