1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
#pragma warning (disable:4996)
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#define SIZE 5
/* Function prototypes
*/
// Function to prompt for and read a numeric score
// Returns an integer score as read in using scanf
int getScore();
// Function to convert a numeric score to a letter grade
// Returns the letter grade
char convertGrade(int numScore);
// IN: Student exam score
// Function to display a message for valid or invalid grade.
void showGrade(int numScore, char letterGrade);
// IN: Original student score
// IN: Corresponding letter grade
int main()
{
int numScore;
char letterGrade;
while (numScore != 1000)
{
numScore = getScore();
letterGrade = convertGrade(numScore);
showGrade( numScore, letterGrade);
if (letterGrade == 'Z')
{
printf ("Terminating program\n");
}
}
}
int getScore()
{
int numScore;
printf("Welcome to the Score Converter.\n\n");
printf("Please enter a numeric value.\n");
printf("Press any key to exit:\n");
scanf("%d", &numScore);
return (numScore);
}
char convertGrade(int numScore)
{
int i;
static int minScores[SIZE] // minimum scores for a grade range
= {90, 80, 70, 60, 0};
static int maxScores[SIZE] // maximum scores for a grade range
= {100, 89, 79, 69, 59};
static char grades[SIZE] // grade for the current grade range
= {'A', 'B', 'C', 'D', 'F'};
for (i=0; i<SIZE; i++)
{
if (numScore<=maxScores[i] && numScore>=minScores[i])
}
return grades[i];
}
void showGrade(int numScore, char letterGrade)
{
if (letterGrade == 'Z')
{
printf ("Sorry. Score invalid.\n");
}
else
{
printf ("The score %d has received a letter grade of %c.\n", numScore, letterGrade);
}
}
| |