We're writing a program in class using data structures and arrays and I'm stuck on writing a loop to find the students' highest test score. I only return the first student's ID, test score, and grade. For some reason unknown to me I'm not actually looping through all 12 or so records. Can you please advise? Thank you.
Code:
#include <stdio.h>
#define MAX_ENTRIES 50
struct records
{ //declare my student records structure
int ID; //the student's ID number
int test_score; //the student's test score
char grade; //the student's letter grade of aforementioned test score
};
struct records high_ID_func (struct records students[], int count);
int main (void)
{
struct records students[MAX_ENTRIES];
struct records high_student; /*the student with the highest test
score*/
int count;
int i;
high_student=high_ID_func(students, count);
printf("Student %i received the high score of %i, %c\n", students[i].ID, students[i].test_score, students[i].grade);
return 0;
} //end main
struct records high_ID_func (struct records students[], int count)
{
int i = 0; //use this to loop array elements
int index = 0;
float high_score;
//Set up the highest test score
high_score = students[0].test_score;
while (i < count)
{
if( high_score < students[i].test_score )
high_score = students[i].test_score;
index = i;
++i;
}
return students[i];
} //end function to find the highest test score
Here's the input data:
1653
77
1945
72
1020
50
1955
92
1030
40
1200
72
1500
91
1100
90
1900
81
1005
95
1790
43
1800
85
0