newbie question on converting numeric grades to letter grades
Can anyone help me. I am working on a program that reads from a text file, then displays the names and grades on the screen. This is working but I need to convert the number grades to letter grades...This is where I need help. '
Does anyone know how to do this???
Jose
my input text file named:grades.txt is below.........
........................
Jones
55
Brown
81
Smith
89
Alazar
93
Forster
63
Joplin
67
Grey
33
@
...................
screen output below....
******************************
NAME GRADE
-----------------------
Jones 55
Brown 81
Smith 89
Alazar 93
Forster 63
Joplin 67
Grey 33
*******************************
...........................
press 'ENTER' key to continue...
............................
and my program code is below.....
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX 10
#define MAXN 10
void main (void)
{
display_grades();
}
void display_grades()
{
char ch;
char lettergrade[MAXN];
FILE *myFile;
//char student[MAXN][MAX];
//int grade[MAXN][MAX];
char student[MAXN][MAX], grade[MAXN][MAX];
int i;
int j;
//set file path
myFile = fopen ("c:\\temp\\grades.txt","r");
//display grades
printf ("\n");
printf ("\n");
printf ("\n");
printf (" ******************************\n");
printf (" NAME GRADE \n");
printf (" ----------------------- \n");
i=0;
fscanf (myFile, "%s", student[0]);
//...until last ending character in file
while (student[i][0] != '@' && i < MAXN -1)
{
fscanf (myFile, "%s", grade[i]);
//convert to letter grade***Not working
if (grade[i] >= 90)
lettergrade[i] = 'A';
else if (grade[i] >= 80)
lettergrade[i] = 'B';
else if (grade[i] >= 70)
lettergrade[i] = 'C';
else if (grade[i] >= 60)
lettergrade[i] = 'D';
else lettergrade[i] = 'F';
//end of conversion
i++;
fscanf (myFile, "%s", student[i]);
}
for (j=0; j<i; j++)
printf (" %s %s \n", student[j], grade[j]);
fclose (myFile);
printf (" *******************************\n");
//add extra lines
printf ("\n");
printf ("\n");
printf ("\n");
printf ("\n");
printf ("\n");
printf ("press 'ENTER' key to continue...\n");
scanf ("%c",&ch);
}