multidimensional array help

I'm trying to create a multidimensional arrays here that is 20 by 10, each row displaying (1, 0, 0, 0, 0, 0, 0, 0, 0, 2) consecutively. But I wasnt able to get it to display the arrays the way I wanted. What is the best solution here?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
  #include <iostream>
using namespace std;

int main(){
	int mulArrays[20][10] = {
		(1, 0, 0, 0, 0, 0, 0, 0, 0, 2),
		(1, 0, 0, 0, 0, 0, 0, 0, 0, 2),
		(1, 0, 0, 0, 0, 0, 0, 0, 0, 2),
		(1, 0, 0, 0, 0, 0, 0, 0, 0, 2),
		(1, 0, 0, 0, 0, 0, 0, 0, 0, 2),
		(1, 0, 0, 0, 0, 0, 0, 0, 0, 2),
		(1, 0, 0, 0, 0, 0, 0, 0, 0, 2),
		(1, 0, 0, 0, 0, 0, 0, 0, 0, 2),
		(1, 0, 0, 0, 0, 0, 0, 0, 0, 2),
		(1, 0, 0, 0, 0, 0, 0, 0, 0, 2),
		(1, 0, 0, 0, 0, 0, 0, 0, 0, 2),
		(1, 0, 0, 0, 0, 0, 0, 0, 0, 2),
		(1, 0, 0, 0, 0, 0, 0, 0, 0, 2),
		(1, 0, 0, 0, 0, 0, 0, 0, 0, 2),
		(1, 0, 0, 0, 0, 0, 0, 0, 0, 2),
		(1, 0, 0, 0, 0, 0, 0, 0, 0, 2),
		(1, 0, 0, 0, 0, 0, 0, 0, 0, 2),
		(1, 0, 0, 0, 0, 0, 0, 0, 0, 2),
		(1, 0, 0, 0, 0, 0, 0, 0, 0, 2),
		(1, 0, 0, 0, 0, 0, 0, 0, 0, 2),
	};

	for (int x = 0; x < 20; x++){
		cout << endl;
		for (int y = 0; y < 10; y++){
			cout << mulArrays[20][10];
		}
	}cout << endl;

	system("pause");
	return 0;
}
Replace parenthesis with curly braces when making the array. To print, the loop should look like this:

1
2
3
4
5
6
	for (int x = 0; x < 20; x++){
		for (int y = 0; y < 10; y++){
			std::cout << mulArrays[x][y];
		}
	    std::cout << std::endl;
    }
It doesnt really work. Instead of getting the default (1, 0, 0, 0, 0, 0, 0, 0, 0, 2) on every row, I get the first two rows of {2,2,2,2,2,2,2,2} and the rest of the rows of {0,0,0,0,0,0,0,0,0}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
using namespace std;

int main(){
	int mulArrays[20][10] = {
		(1, 0, 0, 0, 0, 0, 0, 0, 0, 2),
		(1, 0, 0, 0, 0, 0, 0, 0, 0, 2),
		(1, 0, 0, 0, 0, 0, 0, 0, 0, 2),
		(1, 0, 0, 0, 0, 0, 0, 0, 0, 2),
		(1, 0, 0, 0, 0, 0, 0, 0, 0, 2),
		(1, 0, 0, 0, 0, 0, 0, 0, 0, 2),
		(1, 0, 0, 0, 0, 0, 0, 0, 0, 2),
		(1, 0, 0, 0, 0, 0, 0, 0, 0, 2),
		(1, 0, 0, 0, 0, 0, 0, 0, 0, 2),
		(1, 0, 0, 0, 0, 0, 0, 0, 0, 2),
		(1, 0, 0, 0, 0, 0, 0, 0, 0, 2),
		(1, 0, 0, 0, 0, 0, 0, 0, 0, 2),
		(1, 0, 0, 0, 0, 0, 0, 0, 0, 2),
		(1, 0, 0, 0, 0, 0, 0, 0, 0, 2),
		(1, 0, 0, 0, 0, 0, 0, 0, 0, 2),
		(1, 0, 0, 0, 0, 0, 0, 0, 0, 2),
		(1, 0, 0, 0, 0, 0, 0, 0, 0, 2),
		(1, 0, 0, 0, 0, 0, 0, 0, 0, 2),
		(1, 0, 0, 0, 0, 0, 0, 0, 0, 2),
		(1, 0, 0, 0, 0, 0, 0, 0, 0, 2),
	};

	for (int x = 0; x < 20; x++){
		for (int y = 0; y < 10; y++){
			cout << mulArrays[x][y];
		}
		cout << endl;
	}

	system("pause");
Last edited on
Oh wait nvm it worked. I forgot to replace with curly brackets. Silly me XD thx for the help.
Topic archived. No new replies allowed.