2020-10-20 19:30:51 -05:00
|
|
|
#include <stdio.h>
|
2020-10-21 20:20:52 -05:00
|
|
|
#include <stdlib.h>
|
2020-10-20 19:30:51 -05:00
|
|
|
|
|
|
|
int main() {
|
2020-10-22 22:59:54 -05:00
|
|
|
printf("Please enter a whole number percentage (0-100): ");
|
2020-10-21 20:20:52 -05:00
|
|
|
char inputText[4];
|
|
|
|
fgets(inputText, 4, stdin);
|
|
|
|
printf("inputText: %s\n", inputText);
|
|
|
|
long int input;
|
|
|
|
input = strtol(inputText, NULL, 0);
|
2020-10-22 22:59:54 -05:00
|
|
|
printf("input: %li\n", input);
|
2020-10-20 19:30:51 -05:00
|
|
|
|
2020-10-20 19:56:12 -05:00
|
|
|
if ((input >= 0) && (input <= 100)) {
|
|
|
|
char letter;
|
2020-10-20 20:54:24 -05:00
|
|
|
int inputRange = input/10;
|
|
|
|
|
|
|
|
switch(inputRange) {
|
|
|
|
case 10:
|
|
|
|
case 9:
|
|
|
|
letter = 'A';
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
letter = 'B';
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
letter = 'C';
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
letter = 'D';
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
default:
|
|
|
|
letter = 'F';
|
2020-10-20 19:56:12 -05:00
|
|
|
}
|
2020-10-20 20:54:24 -05:00
|
|
|
|
2020-10-20 19:56:12 -05:00
|
|
|
printf("Your letter grade is %c\n", letter);
|
2020-10-22 22:59:54 -05:00
|
|
|
return 0;
|
2020-10-20 19:30:51 -05:00
|
|
|
} else {
|
2020-10-20 19:56:12 -05:00
|
|
|
printf("ERROR: Input must be no more than 100 and no less than 0\n");
|
|
|
|
return 1;
|
2020-10-20 19:30:51 -05:00
|
|
|
}
|
2020-10-21 20:20:52 -05:00
|
|
|
}
|