diff --git a/letter-grade.c b/letter-grade.c index f05ffbc..ae6f968 100644 --- a/letter-grade.c +++ b/letter-grade.c @@ -5,19 +5,24 @@ int main() { scanf("%i", &input); printf("Your input was: %i\n", input); - char letter; - if ((input/10) >= 9) { - letter = 'A'; - } else if ((input/10) >= 8) { - letter = 'B'; - } else if ((input/10) >= 7) { - letter = 'C'; - } else if ((input/10) >= 6) { - letter = 'D'; + if ((input >= 0) && (input <= 100)) { + char letter; + if ((input/10) >= 9) { + letter = 'A'; + } else if ((input/10) >= 8) { + letter = 'B'; + } else if ((input/10) >= 7) { + letter = 'C'; + } else if ((input/10) >= 6) { + letter = 'D'; + } else { + letter = 'F'; + } + printf("Your letter grade is %c\n", letter); } 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; } \ No newline at end of file