简体   繁体   English

我不明白二维模量c ++

[英]I can't understand the 2d modulus c++

hey guys need help with this piece of code every time I run this it. 嘿,每次我运行这段代码时,他们都需要帮助。 the compiler outputs all on one line. 编译器在一行上全部输出。 I am trying to put in checkerboard format which is 8x8 but the program gives me 1x16 . 我正在尝试使用8x8的棋盘格格式,但是程序给了我1x16。 Try running it and see what it gives you. 尝试运行它,看看它能为您带来什么。 I'm using codeblocks on windows 7. 我在Windows 7上使用代码块。
#include #include #include #include

using namespace std;
class CheckerBoard{
public:
    void initBoard()
    {
        for(int y=0; y<8; y++)
        {
            for(int x=0; x<8; x++)
            {
                if(((x+y)%2)==0)
                {
                    board[y][x]='.';
                }
                else
                {
                    board[y][x]='*';
                }
            }
        }

    }
    void printBoard()
    {
        for(int y=0; y<8; y++)
        {
            for(int x=0; x<8; x++)
            {
                cout<< board[y][x];
            }
        }
    }

private:
    char board[8][8] ;
};


int main()
{
    CheckerBoard checkerBoard;
    checkerBoard.initBoard();
    checkerBoard.printBoard();
    return 0;
}

Add new line to the end of outer loop in printBoard : printBoard的外循环末尾添加新行:

void printBoard()
{
    for(int y=0; y<8; y++)
    {
        for(int x=0; x<8; x++)
        {
            cout<< board[y][x];
        }
        cout << std::endl;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM