#include <stdio.h>
int main()
{
int score;
printf("Input score: "); scanf("%d", &score);
if ((score < 0) || (score > 100))
printf("Invalid score input!\n");
else
{
if (score >= 90) printf("Grade = A\n");
else if (score >= 80) printf("Grade = B\n");
else if (score >= 70) printf("Grade = C\n");
else if (score >= 60) printf("Grade = D\n");
else printf("Grade = F\n");
}
return 0;
}
|
- It turns out to be unnecessary. Because we know that the else
part will always not satisfy the if condition.
- Why? The first if's condition is
((score < 0) || (score > 100)). Thus, the else part would be processed
if the score was within 0 to 100. The 100 cap is therefore not necessary.
- This is also the reason why we don't cap the B, C, and D grade conditions as well.
|