简体   繁体   中英

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 . Try running it and see what it gives you. I'm using codeblocks on windows 7.
#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 :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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