在2D字符数组中打印带有线条的板

时间:2016-10-17 20:16:02

标签: c++11 multidimensional-array control-flow

#include <iostream>

using namespace std;

//prints the board with labels for options.
void print(const char board[3][3])    //function prototype
{
   for(int Row = 0; Row < 3; ++Row)
   {
      for(int Col =0; Col < 3; ++Col)
      {
         cout << board[Row][Col],;
         cout << " | "; 
      }
   }
}

int main()
{      
   int MaxiBoardGrid = 9;

   char board[3][3];

      board[0][0]='A';
      board[0][1]='B';
      board[0][2]='C';
      board[1][0]='D';
      board[1][1]='E';
      board[1][2]='F';
      board[2][0]='G';
      board[2][1]='H';
      board[2][2]='I';

 print(board);

   return 0;     
}


DESIRED OUTPUT;
A|B|C|
------
D|E|F
------
G|H|I

我坚持打印行和上面格式的行。

语言是C ++。

我是2D数组的新手,我正在尝试使用我熟悉的基本代码来打印板。然后为我提议的游戏分配玩家。

感谢。

0 个答案:

没有答案