grid array

Right now this prints out an 8 by 5 grid. Is there a better way to initialize the board instead of copying and pasting {'.'}
Is there a way i can print the same 8 by 5 grid but just getting rid of all the brakcets?


1
2
3
4
5
6
7
8
  char board[8][5] = { {'.','.' ,'.' ,'.' ,'.' },{ '.','.' ,'.' ,'.' ,'.' } ,{ '.','.' ,'.' ,'.' ,'.' } ,{ '.','.' ,'.' ,'.' ,'.' } ,{ '.','.' ,'.' ,'.' ,'.' },{ '.','.' ,'.' ,'.' ,'.' },{ '.','.' ,'.' ,'.' ,'.' },{ '.','.' ,'.' ,'.' ,'.' } };
	for (int i = 0; i < 8; i++) {
		cout << " " << endl;
		for (int j = 0; j < 5; j++) {
			cout << " "<<board[i][j];

		}
	}
One way...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>

int main()
{
	char board[8][5]{};

	for (int i = 0; i < 8; i++) {
		std::cout << " " << std::endl;
		for (int j = 0; j < 5; j++) {
			board[i][j] = '.';
			std::cout << " " << board[i][j];
		}

	}

	std::cout << std::endl;

	return 0;

}
thats exactly what i was looking for. thank you
Topic archived. No new replies allowed.