我一直在爲一個naughts和cross程序做一些編程,而這個板子是一個二維數組。我一直在試圖讓程序重複,如果用戶想重播,但我注意到,重複時,所有的值都保留在數組中。所以我想知道是否有方法來清除我的數組中的所有值。清除二維數組中的值
我在論壇上嘗試了一些以前的問題,但是我發現的一些解決方案似乎並不奏效。
如果有人希望看到代碼只是評論,我會在這裏添加它,我只是不知道是否有必要。
任何幫助將不勝感激。
const int Rows = 4;
const int Columns = 4;
char Board[Rows][Columns] = { {' ', ' ', ' ', ' ' },
{' ', '_', '_', '_' },
{' ', '_', '_', '_' },
{' ', '_', '_', '_' } };
for (int i = 0; i < Rows; ++i)
{
for (int j = 0; j < Columns; ++j)
cout << Board [i][j];
cout << endl;
}
cout << endl << endl;
int row;
int column;
do
{
cout << "Please enter the value of the row you would like to take ";
cin >> row;
}while (row != 0 && row != 1 && row != 2 && row != 3);
do
{
cout << "Please enter the value of the column you would like to take ";
cin >> column;
}while (column != 0 && column != 1 && column != 2 && column != 3);
Board [row][column] = Player1.GetNorX();
for (int i = 0; i < Rows; ++i)
{
for (int j = 0; j < Columns; ++j)
cout << Board [i][j];
cout << endl;
}
顯示數組的定義以及如何填充它。 – 2013-02-28 15:04:33
4x4 naughts和十字架? 「'」和「_」代表什麼? – 2013-02-28 15:08:05
'_'只是在那裏顯示董事會是他們和''在那裏,所以用戶不必輸入一行或一列0.對不起,我應該說, – user2078558 2013-02-28 15:11:31