cout << "Enter the number of rows you want in the first matrix." << endl;
cin >> sizeRow;
cout << "Enter the number of columns in the first matrix." << endl;
cin >> sizeCol;
for ( int i = 0; i < sizeRow; i++ )
{
for ( int j = 0; j < sizeCol; j++ )
{
cout << "Enter element " << i << "," << j << endl;
cin >> element;
a [i][j] = element;
}
}
}
//*******************MAIN*****************************************************
int main ()
{
double matrx1 [MAX][MAX] = {0};
double matrx2 [MAX][MAX] = {0};
on this line --> build_matrx ( matrx1 [][MAX] );
receiving this error: expected primary-expression before ']' token
You don't need to supply the [][MAX] when calling the function. The function is expecting a variable of type double[][MAX]. matrix1 is exactly that. Just call "build_matrx(matrx1);".
Also, for the love of Stroustrup, do the extra effort and type the 'i' in matrix! ò_ó
void build_Matrx ( double [][MAX], int &sizeRow, int &sizeCol ){
//int sizeRow,sizeCol;
double element;
double matrx1 [MAX][MAX];
cout << "Enter the number of rows you want in the first matrix." << endl;
cin >> sizeRow;
cout << "Enter the number of columns in the first matrix." << endl;
cin >> sizeCol;
for ( int i = 0; i < sizeRow; i++ )
{
for ( int j = 0; j < sizeCol; j++ )
{
cout << "Enter element " << i << "," << j << endl;
cin >> element;
matrx1 [i][j] = element;
}
}
}
void printMatrx ( double a [][MAX], int &b, int &c ){
for( int n = 0; n < b; n++)
{
for(int y = 0; y < c; y++)
{
cout << setw(6) << a [n][y];
if (y == ( b - 1 ))
cout << endl << endl;
}
}
}
//*******************MAIN*****************************************************
int main ()
{
double matrx1 [][MAX] = {0};
//double matrx2 [][MAX] = {0};
int sizeRow, sizeCol;
build_Matrx ( matrx1, sizeRow, sizeCol );
printMatrx( matrx1, sizeRow, sizeCol );
The output is:
Enter the number of rows you want in the first matrix.
2
Enter the number of columns in the first matrix.
2
Enter element 0,0
1
Enter element 0,1
2
Enter element 1,0
3
Enter element 1,1
4
0 0
has nothing common with the array matrix1 defined in the main.
You even do not use the first parameter of the function. I think that your task is to use the aaray defined in main, pass it to build_Matrix and fiil it there.