[백준] 9498번

park jinwoo·2022년 12월 6일
0

백준

목록 보기
23/94

https://www.acmicpc.net/problem/9498
시험 점수를 입력받아 90 ~ 100점은 A, 80 ~ 89점은 B, 70 ~ 79점은 C, 60 ~ 69점은 D, 나머지 점수는 F를 출력하는 프로그램을 작성하시오.

<script>
#include <stdio.h>

int main()
{
	int score;
	scanf("%d", &score);

	if (score >= 90) {
		printf("A");
	}
	else if (score >= 80) {
		printf("B");
	}
	else if (score >= 70) {
		printf("C");
	}
	else if (score >= 60) {
		printf("D");
	}
	else {
		printf("F");
	}

	return 0;
}
</script>

❗ 순서를 반대로 60>= 70>= 80>= 90>= 로 설정하면, A가 출력되어야 할 99가 들어가도 60>= 첫 조건을 만족하고 D가 나와버린다.

0개의 댓글