I am a beginner and arrays/functions are giving me a bit of trouble. I a trying to find the highest midterm score and highest final score and pass it back from the function and print. I am also trying to pass the results back as an array. Can anyone help?
Code:
#include <stdio.h>
#include <stdlib.h>
int high(int result, int scores[10][2]);
int main()
{
int highScore[2];
/* equivalent to two variables to hold the maximums */
/* declare array - the first column contains the midterm scores, the second column contains the final scores */
int scores[10][2] = {{78, 90}, {87, 88}, {65, 70}, {56, 100}, {74, 72},
{33, 47}, {87, 88}, {73, 73}, {79, 83}, {95, 89}};
high(highScore [2], scores[10][2]);
printf("Highest midterm score: %d\n", highScore[0]);
printf("Highest final score: %d\n", highScore[1]);
system("pause");
return 0;
}
/* end of main function */
int high(int result[2], int scores[10][2])
{
for (int i = 0; i < 10; i++)
{
if (scores[i][0] > result[0])
{
result[0] = scores[i][0];
}
}
for (int i = 0; i < 10; i++)
{
if (scores[i][1] > result[1])
{
result[1] = scores[i][1];
}
}
return result[2];
}