letter-grade.c: Change if-else chain to switch statement
This commit is contained in:
parent
2beb50bb25
commit
b45e3670cc
@ -7,17 +7,27 @@ int main() {
|
||||
|
||||
if ((input >= 0) && (input <= 100)) {
|
||||
char letter;
|
||||
if ((input/10) >= 9) {
|
||||
int inputRange = input/10;
|
||||
|
||||
switch(inputRange) {
|
||||
case 10:
|
||||
case 9:
|
||||
letter = 'A';
|
||||
} else if ((input/10) >= 8) {
|
||||
break;
|
||||
case 8:
|
||||
letter = 'B';
|
||||
} else if ((input/10) >= 7) {
|
||||
break;
|
||||
case 7:
|
||||
letter = 'C';
|
||||
} else if ((input/10) >= 6) {
|
||||
break;
|
||||
case 6:
|
||||
letter = 'D';
|
||||
} else {
|
||||
break;
|
||||
case 5:
|
||||
default:
|
||||
letter = 'F';
|
||||
}
|
||||
|
||||
printf("Your letter grade is %c\n", letter);
|
||||
} else {
|
||||
printf("ERROR: Input must be no more than 100 and no less than 0\n");
|
||||
|
Loading…
Reference in New Issue
Block a user