/* 2026년 5월 17일
202606017 나경문
10주차 퀴즈 코드 작성 */
#include <stdio.h>
void myinfo() {
printf("202606017 나경문\n");
}
void printPrice(int *price, int menu) {
// 1. 메뉴 번호가 1~4 범위를 벗어나는지 확인하여 예외 처리
if (menu < 1 || menu > 4) {
printf("잘못입력!\n");
return;
}
// 2. 배열 인덱스 대신 포인터 연산을 이용하여 가격 데이터 접근
// 사용자가 입력한 메뉴 번호에서 1을 빼야 올바른 메모리 주소를 찾기 가능
int current_price = *(price + (menu - 1));
// 3. 천 단위 콤마 출력을 위해 값을 1000으로 나누어 몫과 나머지 계산
int quotient = current_price / 1000;
int remainder = current_price % 1000;
// 4. 입력된 메뉴 번호에 매칭되는 메뉴명과 계산된 가격 출력 (주석 4)
switch (menu) {
case 1:
printf("에스프레소:%d,%03d원\n", quotient, remainder);
break;
case 2:
printf("아메리카노:%d,%03d원\n", quotient, remainder);
break;
case 3:
printf("카페라떼:%d,%03d원\n", quotient, remainder);
break;
case 4:
printf("바닐라라떼:%d,%03d원\n", quotient, remainder);
break;
}
}
int main(void)
{
myinfo();
int price[] = { 3000, 4000, 4500, 4800 };
int menu;
scanf("%d", &menu);
printPrice(price, menu);
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: