First of all this is homework. I have been trying to get rid of the errors and usually screw the code up farther and end up coming back to the original code. If you could please give me some direction (in terms I can understand) I would really appreciate it. I do not think our instructor actually expects us to get it, but I still have to try. I am posting now, but will be away from the computer for a while, so I can not comment back right away, Thank you.
#include <stdio.h>
#define MAX 10
main () {
int i;
int num_students;
float total;
long id[MAX]; // Student ID
short midterm[MAX]; // Midterm Grade
short final[MAX]; // Final Grade
float average[MAX]; // Average Grade
float avg_average; // Average of the averages
float diff; // Student's average minus class average
// The average grade is 60% final and 40% midterm
// Compute the course grades, the average course grade,
// and for each student, print out their id, midterm and final grades,
// the average grade, and their difference
i = 0;
// The syntax of this while loop is correct
while (scanf("%i %i %i",&id[i], &midterm[i], &final[i]) != EOF) {
average[i] = midterm[i]*.4 + final[i]*.6;
i++;
}
num_students = i;
for (i = 0; i < num_students; i++) {
total = total + average[i];
}
avg_average = total/num_students;
printf("ID\tMidterm\tFinal\tAvg\tAvgAvg\tDiff\n");
printf("---\t--------\t------\t----\t-------\t-----\n");
for (i = 0; i < num_students; i++) {
diff = avg_average - average[i];
printf("%d\t", id[i]);
printf("%i\t", midterm[i]);
printf("%i\t", final[i]);
printf("%f2.2\t", average[i]);
printf("%f2.2\t",avg_average);
printf("%f2.2\t",diff);
printf("\n");
}
This is the data file I am passing in:
0 94 93 1 88 84 2 99 79 3 78 64 4 66 83 5 78 90 6 90 87 7 23 18 8 55 76 9 48 26 10 87 67 11 97 89 12 100 89 13 88 78 14 67 78 15 87 76 16 77 65 17 83 87 18 89 87
I just do not get the right output in any of the categories.