### Help With Code

Code returns large unwanted numbers as the output of the calculation. It is supposed to calculate the product of two matrices.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115`` ``````#include using namespace std; int main() { int a; int b; int c; int d; int e; int f; int g; int h; int i; int j; int k; int l; int m; int n; int o; int p; int q; int r; int final1 = (a*j) + (b*m) + (c*p); int final2 = (a*k) + (b*n) + (c*q); int final3 = (a*l) + (b*o) + (c*r); int final4 = (d*j) + (e*m) + (f*p); int final5 = (d*k) + (e*n) + (f*q); int final6 = (d*l) + (e*o) + (f*r); int final7 = (g*j) + (h*m) + (i*p); int final8 = (g*k) + (h*n) + (i*q); int final9 = (g*l) + (h*o) + (i*r); int matrix1[3][3] = {{a,b,c},{d,e,f},{g,h,i}}; int matrix2[3][3] = {{j,k,l},{m,n,o},{p,q,r}}; //a b c j k l f1 f2 f3 //d e f * m n o = f4 f5 f6 //g h i p q r f7 f8 f9 int endmatrix [3][3] = {{final1,final2,final3},{final4,final5,final6},{final7,final8,final9}}; cout << "Matrix Multiplication" << endl; cout << "\nEnter Row 1 Column 1 of Matrix 1" << endl; cout << "Input: "; cin >> a; cout << "\n\nEnter Row 1 Column 2 of Matrix 1" << endl; cout << "Input: "; cin >> b; cout << "\n\nEnter Row 1 Column 3 of Matrix 1" << endl; cout << "Input: "; cin >> c; cout << "\n\nEnter Row 2 Column 1 of Matrix 1" << endl; cout << "Input: "; cin >> d; cout << "\n\nEnter Row 2 Column 2 of Matrix 1" << endl; cout << "Input: "; cin >> e; cout << "\n\nEnter Row 2 Column 3 of Matrix 1" << endl; cout << "Input: "; cin >> f; cout << "\n\nEnter Row 3 Column 1 of Matrix 1" << endl; cout << "Input: "; cin >> g; cout << "\n\nEnter Row 3 Column 2 of Matrix 1" << endl; cout << "Input: "; cin >> h; cout << "\n\nEnter Row 3 Column 3 of Matrix 1" << endl; cout << "Input: "; cin >> i; cout << "\n\nEnter Row 1 Column 1 of Matrix 2" << endl; cout << "Input: "; cin >> j; cout << "\n\nEnter Row 1 Column 2 of Matrix 2" << endl; cout << "Input: "; cin >> k; cout << "\n\nEnter Row 1 Column 3 of Matrix 2" << endl; cout << "Input: "; cin >> l; cout << "\n\nEnter Row 2 Column 1 of Matrix 2" << endl; cout << "Input: "; cin >> m; cout << "\n\nEnter Row 2 Column 2 of Matrix 2" << endl; cout << "Input: "; cin >> n; cout << "\n\nEnter Row 2 Column 3 of Matrix 2" << endl; cout << "Input: "; cin >> o; cout << "\n\nEnter Row 3 Column 1 of Matrix 2" << endl; cout << "Input: "; cin >> p; cout << "\n\nEnter Row 3 Column 2 of Matrix 2" << endl; cout << "Input: "; cin >> q; cout << "\n\nEnter Row 3 Column 3 of Matrix 2" << endl; cout << "Input: "; cin >> r; cout << "\n\nThe product of your two matrices is:" << endl; cout << endmatrix[0][0]; cout << " "; cout << endmatrix[0][1]; cout << " "; cout << endmatrix[0][2] << endl; cout << endmatrix[1][0]; cout << " "; cout << endmatrix[1][1]; cout << " "; cout << endmatrix[1][2] << endl; cout << endmatrix[2][0]; cout << " "; cout << endmatrix[2][1]; cout << " "; cout << endmatrix[2][2] << endl; }``````
Your variables that correspond to the alphabet were not initialized and contain arbitrary values.
Remember that everything happens sequentially.

You are doing multiplication and assigning values to your matrix on lines 25-35.

You are not getting the actual data from the user until lines 46+.

This means the math you are doing on lines 25-35 are with random garbage and not with the data the user provided, because you didn't get the user data yet.
OK, so I need to put those lines of code after the user inputs the values?
Thank You So Much Disch, it works now!
Topic archived. No new replies allowed.