Hi,
One of my class assignments is to create a program that receive a .txt file containing a students name and their grades as follows:
John K. 99, 87, 57, 89, 90, 95
Amanda B. Jones 100, 88, 76, 99, 86, 92
etc..
The number of students is unknown until run time. You have to take those grades and average them weighing the first (4) at 10% a piece and the last (2) at 30% each.
Then return an output file with the students name and their letter grade A,B,C,D,F based on their computed score. In addition, on screen it needs to display the average scores for each Q1, Q2, etc. as well as the minimum and maximum for each test on the screen.
I am having a hard time in assigning the scores to a variable so that they can then be computed as an average and then used to determine a letter grade. I have begun to write the code and am a bit stuck..here's what I have so far:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
typedefstruct
{
char fname[30];
char minitial[1];
char lname[100];
int q1, q2, q3, q4, mid, final;
} Student;
int main()
{
const int STUDENTSMAX = 100;
Student students[STUDENTSMAX];
int i = 0;
char fname[30];
FILE *ifp, *ofp;
printf("Enter input .txt file name\n");
scanf("%s",fname);
strcat(fname,".txt");
ifp = fopen(fname,"r");
ofp = fopen("output.txt", "w");
if(ifp == NULL)
{
printf("Error while opening the file.\n");
exit(EXIT_FAILURE);
}
if (ofp == NULL)
{
printf("An error has been generated while attempting to open the output file");
fclose(ofp);
exit(1);
}
while(!feof(ifp))
{
fscanf(ifp, "%s, %s, %d, %d, %d, %d, %d, %d", students[i].fname, students[i].lname, &students[i].q1, &students[i].q2, &students[i].q3, &students[i].q4, &students[i].mid, &students[i].final);
printf("%s %s %d, %d, %d, %d, %d, %d\n\n", students[i].fname,students[i].lname,students[i].q1,students[i].q2,students[i].q3,students[i].q4,students[i].mid,students[i].final);
}
printf("\n");
printf("\n");
fclose(ifp);
}
Any sort of advice or direction would be helpful. Thank you!!!