letter-grade.c: Check if input is between 0 and 100 (inclusive)
This commit is contained in:
parent
bd022c5f22
commit
2beb50bb25
@ -5,19 +5,24 @@ int main() {
|
|||||||
scanf("%i", &input);
|
scanf("%i", &input);
|
||||||
printf("Your input was: %i\n", input);
|
printf("Your input was: %i\n", input);
|
||||||
|
|
||||||
char letter;
|
if ((input >= 0) && (input <= 100)) {
|
||||||
if ((input/10) >= 9) {
|
char letter;
|
||||||
letter = 'A';
|
if ((input/10) >= 9) {
|
||||||
} else if ((input/10) >= 8) {
|
letter = 'A';
|
||||||
letter = 'B';
|
} else if ((input/10) >= 8) {
|
||||||
} else if ((input/10) >= 7) {
|
letter = 'B';
|
||||||
letter = 'C';
|
} else if ((input/10) >= 7) {
|
||||||
} else if ((input/10) >= 6) {
|
letter = 'C';
|
||||||
letter = 'D';
|
} else if ((input/10) >= 6) {
|
||||||
|
letter = 'D';
|
||||||
|
} else {
|
||||||
|
letter = 'F';
|
||||||
|
}
|
||||||
|
printf("Your letter grade is %c\n", letter);
|
||||||
} else {
|
} else {
|
||||||
letter = 'F';
|
printf("ERROR: Input must be no more than 100 and no less than 0\n");
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Your letter grade is %c\n", letter);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user