unexpected results

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
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 i = 0; i < b; i++)
		{
	   for(int j = 0; j < c; j++)
			{
				cout <<  setw(6) << a [i][j];
				if ( i == ( c - 1 ) )
	   					cout << endl << endl;
			}
		}

}
//*******************MAIN*****************************************************
int main ()
{
     double matrx1 [][MAX] = {0};
     //double matrx2 [][MAX] = {0};
     int sizeRow, sizeCol = 0;


          build_Matrx ( matrx1, sizeRow, sizeCol );

          cout << endl<< endl;

          cout << sizeRow << sizeCol;
          getch();
          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


22 0 04.24399e-314

3.1386e-307

Not sure whats wrong here. Any suggestions?
In build_Matrx() you stored entered values into local matrx1, after exit from that function this matrix is destroyed.

In printMatrx() you use different matrx1 - it contains garbage.
Topic archived. No new replies allowed.