void John_is_3D(int dimx,int dimy,int dimz)
{

      int ***John; // pointer to pointer to pointer
      John = new int**[dimx]; // array of pointers to pointers


      for(int x = 0;x<dimx;x++)
{
        John[x] = new int*[dimy];




       for(int y = 0;y<dimy;dimz++)
{

         John[x][y] = new int[dimz];



     for(int z = 0;z<dimz;z++)
{
         John[x][y][z]= x*y*z;
         cout << John[x][y][z];

}

}
     cout <<endl;
}



}

can someone please point out whats wrong in here. I should dynamicly alloc 3d array and fill it with multiplication table

Other than poor formating, I don't see anything wrong with how you allocated the array. The values in the array are something else.

void John_is_3D(int dimx, int dimy, int dimz)
{

    int ***John; // pointer to pointer to pointer
    John = new int**[dimx]; // array of pointers to pointers


    for (int x = 0; x<dimx; x++)
    {
        John[x] = new int*[dimy];
        for (int y = 0; y<dimy; dimz++)
        {
            John[x][y] = new int[dimz];
            for (int z = 0; z<dimz; z++)
            {
                John[x][y][z] = x*y*z;
                cout << John[x][y][z];

            }

        }
        cout << endl;
    }



}

Edited 2 Years Ago by Ancient Dragon

then why when I run program all I get is endless 0's ?

Simple math says that many of the cells will contain 0 since x, y, or z will be 0, and 0 times anything results in 0. However, there's a bug in the code:

for (int y = 0; y<dimy; dimz++)

Notice the increment step modifies dimz rather than y.

This question has already been answered. Start a new discussion instead.