if...else is used to run different code blocks depending on a condition. Checking login access, assigning a grade based on a score, checking whether stock is available — they all follow this same logic pattern.
c
#include <stdio.h>
int main() {
int score = 72;
if (score >= 80) {
printf("Grade A");
} else if (score >= 60) {
printf("Grade B");
} else {
printf("Try again");
}
return 0;
}The program checks the conditions from top to bottom. score >= 80 is false, so it moves on to check the next condition, and score >= 60 is true, so Grade B gets printed.
You should see
Grade BInfo
Put the stricter condition first. In grade logic, score >= 60 if you check this first, even students scoring above 80 could end up landing in B.