Hi,
I am writing a program to read in grades from a text file and calculate the grade point average from a list of grades. I have the basic code done, i have not started to calculate the average or write to the file because there's no point until i figure this problem out although I'm sure its something simple. Any help would be great
Code:
#include <stdio.h>#include <stdlib.h>
#define Agrade 4.0
#define Bgrade 3.4
#define Cgrade 2.8
#define Dgrade 2.2
#define Egrade 1.6
#define Fgrade 1.0
int main ()
{
FILE *fopen(), *fp1, *fp2;
float GPA=0.0;
int c,line;
char filename1[80],filename2[80],name[80],grade[20];
printf("Please enter the name of the file you wish to open:");
gets(filename1);
printf("Please enter the name of the file you would like to store the information in:");
gets(filename2);
fp1= fopen(filename1,"r");
fp2= fopen(filename2,"w");
if(fp1==NULL)
{
printf("The File %s could not be opened for reading", filename1);
exit(0);
}
if(fp2==NULL)
{
printf("The File %s could not be opened for writing", filename2);
exit(0);
}
else
c=getc(fp1);
while(c!= EOF && line!='\n')
{
fscanf(fp1, "%s %c",&name,&grade);
if (grade=='A'){
GPA+Agrade;
}
if (grade=='B'){
GPA+Bgrade;
}
if (grade=='C'){
GPA+Cgrade;
}
if (grade=='D'){
GPA+Dgrade;
}
if (grade=='E'){
GPA+Egrade;
}
if (grade=='F'){
GPA+Fgrade;
}
exit(0);
}
return 0;
}