dynamical array alocation and displaying it

Hello i have to do this:
Write a function that takes 3 arguments, a length, width and height, dynamically allocates a 3-dimensional array with those values and fills the 3-dimensional array with multiplication tables. Make sure to free the array when you are done.

this is 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>

using namespace std;

void multi (int ***, int, int, int);
  
int main ()
{
  int ***board, x_axis, y_axis, z_axis;
  cout << "Enter the number of x axis: " << endl;
  cin >> x_axis;
  cout << "Enter the number of y axis: " << endl;
  cin >> y_axis;
  cout << "Enter the number of z axis: " << endl;
  cin >> z_axis;
  cout << endl;
  
  board = new int** [x_axis];
  for (int x = 0; x < x_axis; x++)
    board [x_axis] = new int* [y_axis]; 
      for (int y= 0; y < y_axis; y++)
	board [x_axis][y_axis] = new int [z_axis];

  multi (board, x_axis, y_axis, z_axis);
  cin.get();
  return 0;
}

void multi (int ***p, int x_a, int y_a, int z_a)
{
 for (int x = 0; x < x_a; ++x)
 {
    for (int y = 0; y < y_a; ++y)
    {
	for (int z = 0; z < z_a; ++z)
	{
	    p [x] [y] [z] = x * y * z; 
	}
    }
 }
 cout << "multi table : " << endl;
 for (int a = 0; a < x_a; ++a)
 {
    for (int b = 0; b < y_a;++b)
    {
	for (int c = 0; c < z_a; ++c)
	{
	    cout << "[" << a << "] [" << b << "] [" << c << "] = ";
	    cout << p [a] [b] [c] << " ";
	    cout << "\n";
	}
    }
 }
}

dont rly know where to put the
 
delete [] board;


and whet its gets to calling the function multi i get
 
Segmentation fault (core dumped)


so i am stuck.
Last edited on
Topic archived. No new replies allowed.