Two Matrices

I have two matrices that are input from data files. I'm trying to find the maximum value in the FIRST matrix only. I wrote some code that I thought would do something like this, but the program crashes when I test it. Also, this is in a switch statement as a menu option. Any suggestions?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
switch (menuChoice)
{
   case '1':
      maximumValue (a, s, t);
   break;



void maximumValue     (double a[][20], int s, int t)
{
   int i, j;
   double max;
   
   max = a[0][0];
   for (i=0; i <= s-1; i++)
   {
      for (j=0; j <= t-1; i++)
	  {
       if (a[i][j] > max)
           max = a[i][j];
	  }
   }
      cout << "     Maximum value = " << fixed << setprecision(2) << setw(8) << right << max << endl;
}
Last edited on
Try removing the <= and just having <

EX
1
2
3
for (int i = 0; i < s; i++)
   for (int j = 0; j < t; j++)
Last edited on
Just tried it, program still crashes. I think there's some way I'm not seeing to specify the first matrix.
The typical way is:

for(int j = 0; j < t; ++j)

This avoids the confusing '-1'.


That said... your problem is probably because each loop is incrementing i, when the inner loop should be incrementing j.
Last edited on
Good catch on the second ++i, did not even notice that, that would probably fix it.
My problem was the i++ where it should have been j++ like you said. Thanks a lot.
Topic archived. No new replies allowed.