Hi,
Need some help on this one. I am writing a program using structures and arrays for students grades. I am getting the input from a file and I am suppossed to print out the data, then print out the max score, min score, and average score of each quiz taken. Here is the code I have made so far.
Code:
#include <stdio.h>
/* Global Declarations */
typedef struct
{
char nameFirst[20];
char nameLast[20];
int id;
int quiz[4];
int exam;
} STUDENT;
int main (void)
{
STUDENT stuAry[50];
STUDENT highest;
STUDENT lowest;
STUDENT average;
FILE *fpData;
int i = 0;
if ((fpData = fopen("lab5.txt", "r")) == NULL) // <-- OPENS lab5.txt FILE
{
printf("\a*ERROR OPENING lab5.txt\n");
return (100);
} /* IF OPEN */
printf("--------------------------------------------------------------------\n");
printf("\t\t\t\t DATA\n");
printf("--------------------------------------------------------------------\n");
printf("\nNAME\t\t\tID\tQUIZ1\tQUIZ2\tQUIZ3\tQUIZ4\tEXAM\n\n");
while ((fscanf (fpData, "%s%s%d%d%d%d%d%d", &stuAry[i].nameFirst, &stuAry[i].nameLast, &stuAry[i].id, &stuAry[i].quiz[0], &stuAry[i].quiz[1], &stuAry[i].quiz[2], &stuAry[i].quiz[3], &stuAry[i].exam))>0){
printf("%-10s ", stuAry[i].nameFirst);
printf("%-10s", stuAry[i].nameLast);
printf("\t%d\t", stuAry[i].id);
printf("%d\t", stuAry[i].quiz[0]);
printf("%d\t", stuAry[i].quiz[1]);
printf("%d\t", stuAry[i].quiz[2]);
printf("%d\t", stuAry[i].quiz[3]);
printf("%d\n", stuAry[i].exam);
i++;
}
printf("\n--------------------------------------------------------------------\n");
printf("\t\t\t\t STATISTICS\n");
printf("--------------------------------------------------------------------\n");
if (fclose(fpData == EOF) // <--CLOSES lab5.txt FILE
{
printf("\aERROR OPENING lab5.txt\n");
return (102);
}
return 0;
}
Any help to start me off in the right direction would be great. Thanks in advance.