I am to create a program that takes data from an input file and assigns a grade basd on averages. The program works great and everything, but I have one issue...
Here is my code:
Code:
/* MAE 9 Final Assignment */
#include <stdio.h>
#include <math.h>
void prob1(void);
void prob2(void);
main()
{
int menu;
printf("Enter The Function Number To Execute (1-2): ");
scanf("%d", &menu);
switch(menu){
case 1:
prob1();
break;
default:
printf("prob%d() does not exist.\n", menu);
}
exit(0);
}
void prob1(void)
{
FILE *infile, *outfile;
char text[81], ch_grade;
double average;
int lines, k, score [5], i_ave, name[30], last_name[30];
infile = fopen("score.dat", "r");
outfile = fopen("grades.dat", "w");
if(infile == NULL || outfile == NULL){
printf("***File Opening Error!***\n");
exit(101);
}
lines=0;
while(fgets(text,81,infile)!=NULL){
lines++;
if (lines%2 !=0){
sscanf(text, "%s %s",
name, last_name);
}else {
sscanf(text, "%d %d %d %d %d",
score, score+1, score+2, score+3, score+4);
for(k=0, average=0.0; k<5; k++)
average += (double)score[k];
average /= 5.0;
i_ave = (int)(average + 0.5);
if(i_ave = 100) ch_grade = 'A';
else if(i_ave >= 90) ch_grade = 'A';
else if(i_ave >= 80) ch_grade = 'B';
else if(i_ave >= 65) ch_grade = 'C';
else if(i_ave >= 55) ch_grade = 'D';
else ch_grade = 'F';
printf("Student %s %s: ", name, last_name);
printf("Average = %5.1f;", average);
printf(" Grade = %c.\n", ch_grade);
fprintf(outfile, "Student %s %s: ", name, last_name);
fprintf(outfile, "Average = %5.1f;", average);
fprintf(outfile, " Grade = %c.\n", ch_grade);
}
}
fclose(infile);
fclose(outfile);
exit(0);
}
I need the grade of 100% to print out with an "A+", but when I type in the plus I get warning messages. I tried it once just to see and once the plus was in just the first line, all the outputs got changed to just pluses.
Ex:
Student 1, Grade = +
Student 2, Grade = +
and so on...
I only need the 100% student to print out an "A+" what do I need?
Thank you