Need help with Arrays and the Highest element of an Array.

Suppose you have a text file that looks like this,

Alan Blandon 1, 2, 3, 4, 5
Marvin Alvarez 2, 3, 4, 5, 6

There is a 1D Array for names and a 2D Array for scores. How would you display the name of the student who received the highest total score? Below I have a segment of my source code.

1
2
3
4
5
6
7
8
9
10
11
void calcHighestScore(){
int highest = 0;
for(int i=0; i<NUM_OF_STUDENTS; i++){
int total = 0;
for(int j=0; j<NUM_OF_SCORES; j++){
total+=studentScores[i][j];
}
if(total>highest)
highest=total;
}
}


I know this calculates the highest score but how would you go about displaying the name related to that score. Any help is appreciated.
Last edited on
You need to get the index of the highest score and this index you can use to get the name of the student.
Do you have to use separate arrays?
Would be easier if you could use structs.
We have to use separate arrays. So the index you say, but the array is a 2D Array so I would have to take the sum of the individual scores. But wouldn't that just be a variable not an array so how would I use that index?
Last edited on
The row with the highest score is the index of the names.
For example:
1
2
3
4
5
6
7
8
int scores[3][3] = 
{
  {1,2,3},
  {1,2,2},
  {2,1,4}
};

string names[3] = {"Anna", "Ellie", "Cassandra"};


Index of the row with the highest score is 2.
So the student with the highest score is names[2] => Cassandra
Topic archived. No new replies allowed.