[英]I can't understand the 2d modulus c++
嘿,每次我運行這段代碼時,他們都需要幫助。 編譯器在一行上全部輸出。 我正在嘗試使用8x8的棋盤格格式,但是程序給了我1x16。 嘗試運行它,看看它能為您帶來什么。 我在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;
}
在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.