Find the highest and lowest value of a multidimensional array

Hi, I had another questions in regards to a topic I previously posted. I was working on finding the highest and lowest value of a multi-dimensional array which I was able to get help figuring out. I was only able to figure out how to determine the highest and lowest value for each student after all the information was successfully inputted. However, I was wondering if someone could please help me figure out how to determine the highest and lowest value after the information for each student has been inputted. Could someone please help me or give me a hint on how to do this? Below I have inputted the code of the previous code. Thank you
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
  //Ask the user to input the test scores of 5 students for 3 tests.

//Then for each student compute the average test score,

//as well as the student's highest and lowest test score

//and print them out.

#include <iostream>
using namespace std;

const int STUDENTS = 5;
const int TESTS = 3;

int main ()
{
    int score[STUDENTS][TESTS];
    int s; //Represents students
    int t; //Represents tests
    int highest;
    int lowest;
    float Average = 0;
    
    
    cout << "Input tests scores of 5 students for 3 tests: \n\n";
    
    for (s=0; s < STUDENTS; s++)
    {
        int Total = 0;
        
        for (t=0; t < TESTS; t++)
        {
            cout << "Student #" << s+1 << " - Test #" << t+1 << ": ";
            cin >> score[s][t];
            Total += score[s][t];
        }
        
        Average = float(Total) / TESTS;
        cout << "The average score is " << Average << endl << endl;
        
    }
    
    highest = score[0][0];
        lowest = score[0][0];
    
    cout << "===============================================================================\n\n";
    
        for (s=0; s < STUDENTS; s++)
        {
            for (t=0; t < TESTS; t++)
                {
                if(score[s][t] > highest)
                    highest = score[s][t];
                else
                    if (score[s][t] < lowest)
                    lowest = score[s][t];
                

                    }
            
            cout << "The highest score for student #" << s+1 << " is " << highest << endl;
            cout << "The lowest score for student #" << s+1 << " is " << lowest << endl << endl;
            
            highest = score[s][t];
            lowest = score[s][t];
            
        }

    return 0;
}
If you're wanting to find out the lowest and highest score among the tests, you first have to assume that the highest test score is 0 and the lowest test score is a 100 (assuming max marks of a test is out of 100).

On line 43 and 44
1
2
3
4
highest = score[0][0];
lowest = score[0][0];
highest = 0;
lowest = 100;


Remove lines 64 and 65. I am not sure why you have them there. Consider replacing with
1
2
cout << "highest score: " << highest << std::endl;
cout << "lowest score: " << lowest << std::endl;

to see results.
Hi Fliji885,

Thank you for the response. My apologies if I didn't explain it well but what I meant to say was I am trying to find the highest and lowest test score per student every time a new the the program displays the information for each student. The program I previously displayed only provides the highest and lowest value for each student after all the information is inputted for all five students, however I wanted the highest and lowest values to be displayed after the information is inputted for each student. I re-arranged the code around so it looks a little more clear. It will display the lowest value however not the highest one.
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70

//Ask the user to input the test scores of 5 students for 3 tests.

//Then for each student compute the average test score,

//as well as the student's highest and lowest test score

//and print them out.

#include <iostream>
using namespace std;

const int STUDENTS = 5;
const int TESTS = 3;

int main ()
{
    int score[STUDENTS][TESTS];
    int s; //Represents students
    int t; //Represents tests
    int highest;
    int lowest;
    float Average = 0;
    
    highest = score[0][0];
    lowest = score[0][0];
    
    cout << "Input tests scores of 5 students for 3 tests: \n\n";
    
    for (s=0; s < STUDENTS; s++)
    {
        int Total = 0;
        
        for (t=0; t < TESTS; t++)
        {
            cout << "Student #" << s+1 << " - Test #" << t+1 << ": ";
            cin >> score[s][t];
            Total += score[s][t];
            
            if(score[s][t] > highest)
                highest = score[s][t];
            else
                if (score[s][t] < lowest)
                    lowest = score[s][t];
        }
        
      
        
        Average = float(Total) / TESTS;
        cout << "The average score is " << Average << endl << endl;
        cout << "The highest score for student #" << s+1 << " is " << highest << endl;
        cout << "The lowest score for student #" << s+1 << " is " << lowest << endl << endl;
        
        highest = score[s][t];
        lowest = score[s][t];
        
    }
    
  
    
    cout << "===============================================================================\n\n";
    
    
            
           
  
    return 0;
}



You have to assume that at first, the lowest test score is the highest and the highest is the lowest. Every iteration of the first for loop, reset the lowest and the highest test scores.

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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//Ask the user to input the test scores of 5 students for 3 tests.

//Then for each student compute the average test score,

//as well as the student's highest and lowest test score

//and print them out.

#include <iostream>
using namespace std;

const int STUDENTS = 5;
const int TESTS = 3;

int main ()
{
    int score[STUDENTS][TESTS];
    int s; //Represents students
    int t; //Represents tests
    int highest;
    int lowest;
    float Average = 0;
    
    // highest = score[0][0];     remove
    // lowest = score[0][0];      remove
    
    cout << "Input tests scores of 5 students for 3 tests: \n\n";
    
    for (s=0; s < STUDENTS; s++)
    {
        int Total = 0;
        highest = 0;    // add
        lowest = 100;  // add
        
        for (t=0; t < TESTS; t++)
        {
            cout << "Student #" << s+1 << " - Test #" << t+1 << ": ";
            cin >> score[s][t];
            Total += score[s][t];
            
            if(score[s][t] > highest)
                highest = score[s][t];
            else
                if (score[s][t] < lowest)
                    lowest = score[s][t];
        }
        
      
        
        Average = float(Total) / TESTS;
        cout << "The average score is " << Average << endl << endl;
        cout << "The highest score for student #" << s+1 << " is " << highest << endl;
        cout << "The lowest score for student #" << s+1 << " is " << lowest << endl << endl;
        
        //highest = score[s][t];        remove
        //lowest = score[s][t];         remove
        
    }
    
  
    
    cout << "===============================================================================\n\n";
    
    
            
           
  
    return 0;
}





Input tests scores of 5 students for 3 tests: 

Student #1 - Test #1: 90
Student #1 - Test #2: 80
Student #1 - Test #3: 70
The average score is 80

The highest score for student #1 is 90
The lowest score for student #1 is 70

Student #2 - Test #1: 65
Student #2 - Test #2: 74
Student #2 - Test #3: 63
The average score is 67.3333

The highest score for student #2 is 74
The lowest score for student #2 is 63

Student #3 - Test #1: 15
Student #3 - Test #2: 0
Student #3 - Test #3: 60
The average score is 25

The highest score for student #3 is 60
The lowest score for student #3 is 0

Student #4 - Test #1: 100
Student #4 - Test #2: 69
Student #4 - Test #3: 66
The average score is 78.3333

The highest score for student #4 is 100
The lowest score for student #4 is 66

Student #5 - Test #1: 64
Student #5 - Test #2: 33
Student #5 - Test #3: 73
The average score is 56.6667

The highest score for student #5 is 73
The lowest score for student #5 is 33

===============================================================================

Ohhh ok perfect I get what you mean now. I'll make sure to apply this in future projects as well. Thank you very much for your help!
Topic archived. No new replies allowed.