3D Array printout

Hi, Could you please help with this question. I have a 3d array set up, but when I go to print it out, it skips the first index, i.e. [0][0][0] and I am not sure why. My thought is that I am incrementing 'i' before I should be, if so, could you explain how I can start to print out at [0][0][0]? Thank you.

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

using namespace std;

int main()
{
    int val [3][3][3] =
    {
        {{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}}
    };

    for ( int i = 0; i < 3; i++ )
      for ( int j = 0; j < 3; j++ )
        for ( int k = 0; k < 3; k++ )
      {
         cout << "val [" << i << "][" << j << "][" << k << "]: ";
         cout << val[i][j][k]<< endl;
      }


    return 0;
}
It appears to work as expected. perhaps the first line is scrolling off your screen.

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
val [0][0][0]: 1
val [0][0][1]: 2
val [0][0][2]: 3
val [0][1][0]: 4
val [0][1][1]: 5
val [0][1][2]: 6
val [0][2][0]: 7
val [0][2][1]: 8
val [0][2][2]: 9
val [1][0][0]: 10
val [1][0][1]: 11
val [1][0][2]: 12
val [1][1][0]: 13
val [1][1][1]: 14
val [1][1][2]: 15
val [1][2][0]: 16
val [1][2][1]: 17
val [1][2][2]: 18
val [2][0][0]: 19
val [2][0][1]: 20
val [2][0][2]: 21
val [2][1][0]: 22
val [2][1][1]: 23
val [2][1][2]: 24
val [2][2][0]: 25
val [2][2][1]: 26
val [2][2][2]: 27
omg, yes that was it. really sorry to waste your time.
Topic archived. No new replies allowed.