Trying to store an array inside of another one

I am making a function that finds the inverse of a matrix, so I am using arrays to represent the matrix. I will also be putting my inverse code in a header file for portability and in case someone uses an array name that is not called matrix[3][3], i want the data in that array to be put into my array because my entire function is written using that array name. In my inverse function, when I try to put a matrix with a random name into my array called matrix[3][3], there is an error that says error: expected an expression. It says that under the { , at matrix[3][3] = {.[#include <iostream>

using namespace std;
int row, column;
float det; // determinant
double matrix[3][3];
int key[3][3];
double cofact[3][3];
double flip[3][3];

//void inverse();
int main()
{
for (int k=0;k<3;k++)
{
for(int e=0; e<3; e++)
{
cin >> key[k][e];
}
}
inverse();
} //end of main
void inverse(int key[3][3])
{
for (int i=0; i<3;i++)
for(int j=0; j<3;j++)
matrix[3][3] = { {key[0][0], key[0][1], key[0][2]}, {key[1][0], key[1][1], key[1][2]}, {key[2][0], key[2][1], key[2][2]} };
det = (matrix[0][0]*( (matrix[1][1])*(matrix[2][2]) - (matrix[2][1])*(matrix[1][2]) )) -( matrix[0][1]*( (matrix[1][0])*(matrix[2][2]) - (matrix[2][0])*(matrix[1][2]) )) + (matrix[0][2]*( (matrix[1][0])*(matrix[2][1]) - (matrix[2][0])*(matrix[1][1]) ));
//return det;

cofact[0][0]=(matrix[1][1])*(matrix[2][2]) - (matrix[2][1])*(matrix[1][2]); //diagonal
cofact[0][1]=-( (matrix[1][0])*(matrix[2][2]) - (matrix[2][0])*(matrix[1][2]) );
cofact[0][2]=(matrix[1][0])*(matrix[2][1]) - (matrix[2][0])*(matrix[1][1]);
cofact[1][0]=-( (matrix[0][1])*(matrix[2][2]) - (matrix[2][1])*(matrix[0][2]) );
cofact[1][1]=(matrix[0][0])*(matrix[2][2]) - (matrix[2][0])*(matrix[0][2]); //diagonal
cofact[1][2]=-( (matrix[0][0])*(matrix[2][1]) - (matrix[2][0])*(matrix[0][1]) );
cofact[2][0]=(matrix[0][1])*(matrix[1][2]) - (matrix[1][1])*(matrix[0][2]);
cofact[2][1]=-( (matrix[0][0])*(matrix[1][2]) - (matrix[1][0])*(matrix[0][2]) );
cofact[2][2]=(matrix[0][0])*(matrix[1][1]) - (matrix[1][0])*(matrix[0][1]); // diagonal

flip[0][0] = cofact[0][0];
flip[0][1] = cofact[1][0];
flip[0][2] = cofact[2][0];
flip[1][0] = cofact[0][1];
flip[1][1] = cofact[1][1];
flip[1][2] = cofact[2][1];
flip[2][0] = cofact[0][2];
flip[2][1] = cofact[1][2];
flip[2][2] = cofact[2][2];

cout << "\nThe inverse is " << endl;
cout << (1/det)*(flip[0][0]) << " " << (1/det)*(flip[0][1]) << " " << (1/det)*(flip[0][2]) << endl;


cout << (1/det)*(flip[1][0]) << " "
<< (1/det)*(flip[1][1]) << " "
<< (1/det)*(flip[1][2]) << endl;

cout << (1/det)*(flip[2][0]) << " "
<< (1/det)*(flip[2][1]) << " "
<< (1/det)*(flip[2][2]) << endl;

}][/code]
Topic archived. No new replies allowed.