I tried running this many different ways in attempts to solve the garbage being printed. I am trying to run through the input file, get the testScore, and have the loop determine what the grade is, in the end returning grade
I still get the garbage values. He is what I have using the array. I' thinking I need to be asking for input of testScore for the letterGrade function? but I am not exactly sure how to, and if that is ever correct thinking
You have to set the 'grade' values of all your 'StudentType' objects of your 'grades[]' array.
Therefore you need access to it at your letterGrade() code. So it's best to pass a reference of this into your letterGrade() function. Assuming, you will grading at each invocation of your letterGrade() function a single student, your letterGrade() function looks like this:
The other way is, like your try, passing the whole array to the letterGrade() function. But then it should better named to letterGrades. Also, you need to pass the size of grades[] because plain arrays will be passed as pointers
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
void letterGrades(StudentType grades[], int size)
{
for (int i = 0; i < size; ++i)
{
char grade;
int testScore= grades[i].testScore;
if (testScore >= 90) grade = 'A';
elseif (testScore >= 80) grade = 'B';
elseif (testScore >= 70) grade = 'C';
elseif (testScore >= 60) grade = 'D';
else grade = 'F';
grades[i].grade = grade;
}
}