3D Array Keypad Help.

So I'm trying to output the numbers in the form of the square left hand side keypad you find on some keyboards. Like this:

789
456
123

The only problem is, that my output is this:

789000000
456000000
123000000

I think I know whats the problem, but I can't seem to figure it out, can someone help me?

Here's my code:

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
  #include <iostream>
#include <string>

using namespace std;

int main()
{
	int matrix[3][3][3] = {
		{7, 8, 9},
		{4, 5, 6},
		{1, 2, 3}
	};

	for (int i = 0; i < 3; ++i)
	{
		for (int j = 0; j < 3; ++j)
		{
			for (int n = 0; n < 3; ++n)
			{
				cout << matrix[i][j][n] << "" << flush;
			}
			
		}
		cout << endl;
	}

	cin.clear();
	cin.sync();
	cin.get();

	return 0;
}
Why the three dimensional array? You only initialize part of that array, what about the other elements?

Topic archived. No new replies allowed.