Multi-Dimensional array printing only one dimension.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include "stdafx.h"


#include <iostream>

int main(){
	char grid[7][6];
	int i;
	int j;

	for (i = 0; i < 7; i++){
		for (j = 0; j < 6; j++){

			grid[i][j] = 'O';
			std::cout << grid[i][j];
		}
	}
}

It prints only one line. OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
Why is that?
Last edited on
What do you mean by "only one dimension"?

Your grid has 7*6 elements and the loop both sets and prints every single one of them.

Perhaps you expect to see a linebreak after a row of elements have been printed? If yes, then print linebreaks.
You just missed the curly brackets in the second loop and the new line after it.
do you mean:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
int main(){
	char grid[7][6];
	int i;
	int j;
	
	for (i = 0; i <7; i++){
		for (j = 0; j < 6; j++){
			grid[i][j] = 'O';
			std::cout << grid[i][j];
		}
		std::cout<<endl;
	}
}
Thanks guys!
Topic archived. No new replies allowed.