双面2D阵列打印
Reversi 2D array print
(这是家庭作业)我正在尝试打印一个带有行和列标题的Reversi板。我的问题是,为什么没有打印句号,而是打印"B"answers"W"。有什么建议吗?
#include <iostream>
#include <cstdlib>
using namespace std;
const int BOARD_SIZE = 8, MOVE_SYMBOL = 3;
void PrintBoard(char board[8][8]);
int main(int argc, char* argv[]) {
const int BOARD_SIZE = 8;
char board[BOARD_SIZE][BOARD_SIZE] =
{
{ 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 1, -1, 0, 0, 0 },
{ 0, 0, 0, -1, 1, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0 }
};
PrintBoard(board);
}
// Prints current state of Reversi Board 15L
void PrintBoard(char board[BOARD_SIZE][BOARD_SIZE]) {
char output[MOVE_SYMBOL] = { 'W', ' . ', 'B' };
cout << "n- 0 1 2 3 4 5 6 7";
for (int i = 0; i < BOARD_SIZE; i++) {
cout << "n" << i;
for (int j = 0; j < BOARD_SIZE; j++) {
cout << output[board[i][j] + 1];
}
}
输出:
- 0 1 2 3 4 5 6 7
0
1
2
3 BW
4 WB
5
6
7 Press any key to continue . . .
这是因为witespace会影响你的经期。一个字符是一个单独的位置,所以'.'
而不是' . '
。
相关文章:
- 库特<<恩德尔;不适用于打印 2D 阵列
- 数组类 阵列的打印输出
- 阵列打印功能
- 打印原始阵列和更改的阵列
- 多次打印出整个阵列
- 无法弄清楚为什么我的打印阵列要替换元素
- 阵列无法正确打印 C++
- 如何打印一个字符阵列和其中的特定字符
- C++ Visual 工作室中的逻辑错误.阵列打印的是地址而不是内容
- 指针阵列打印值
- 打印我的字符串阵列时,会遇到细分错误
- 从指针打印动态int阵列中获取怪异的字符
- 无法打印阵列或分配给阵列
- 有没有办法更快地打印2D阵列
- 为什么 2-D 阵列在不应该打印的地方打印 1?
- 按升序打印阵列旨在下降
- 无法以C++打印阵列
- C 打印阵列
- 打印阵列出现错误C++
- 我想在新行打印阵列的每个插槽