Multiplying Matrcies

I need to make two matrices and then multiply them and output. I can input fine but somewhere in the multiplication process it makes the program crash. I don't get an error message and I can't seem to figure out why it doesn't work. Any help is greatly appreciated. Thanks!
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <iostream>
using namespace std;
int main() {

	int n=0,n2=0,n3=0,**x, **y,**z;
	
	cout<<"How many rows do you want in your first matrix?  ";
		cin>>n;
	cout<<"How many columns do you want in your first matrix?  ";
		cin>>n2;
	cout<<"How many columns do you want in your second matrix?  ";
		cin>>n3;
		
	x = new int*[n];
	y = new int*[n2];
	z = new int*[n];

	if(x == NULL) {
		cout<< "Could not allocate memory.  Exiting program.";
		
		return 1;
	}
	if(y == NULL) {
		cout<< "Could not allocate memory.  Exiting program.";
		
		return 1;
	}


	//User input for x
	cout<<"Array 1"<<endl<<endl;
	for (int i=0 ; i < n; i++)
		x[i] = new int [n2];

		for (int i=0 ; i < n; i++ ) 
		{
			for (int j=0 ; j < n2; j++) 
			{
				cout<<"Please input a number for row "<<i<<" and column "<<j<<endl;
					cin>>x[i][j];
			}
		}
		cout<<endl<<endl;

	//User input for y
	cout<<"Array 2"<<endl<<endl;
	for (int i=0 ; i < n2; i++)
		y[i] = new int [n3];

		for (int i=0 ; i < n2; i++ ) 
		{
			for (int j=0 ; j < n3; j++) 
			{
				cout<<"Please input a number for row "<<i<<" and column "<<j<<endl;
					cin>>y[i][j];
			}
		}
		cout<<endl<<endl;

		
	//Multiplying x*y
	for (int row = 0; row < n; row++)
        {
            for (int col = 0; col < n3; col++)
            {
                for(int k = 0; k <n; k++)
                {
                    z[row][col] += x[row][k] * y[k][col];
                }
				cout<<z[row][col] << "	";
            }
			cout<< "\n";
        }
	return 0;
}
new will never return null/nullptr - if it fails to allocate memory, it will throw an exception.

Have you tried stepping through your code with a debugger? Most IDEs have one built in.
Topic archived. No new replies allowed.