Last active
August 29, 2015 14:19
-
-
Save nesffer/c1a523e9ca3d176b5ea6 to your computer and use it in GitHub Desktop.
자판기에 돈 넣고 동전 돌려받자
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 자판기에 돈 넣고 동전 돌려받자 | |
#include <stdio.h> | |
int main() { | |
int coin, price, num, back, five, one; | |
printf("투입할 금액을 입력하세요: "); | |
scanf("%d", &coin); | |
printf("제품의 금액을 입력하세요: "); | |
scanf("%d", &price); | |
printf("제품의 갯수를 입력하세요: "); | |
scanf("%d", &num); | |
if (coin >= price * number) { | |
back = coin - price * num; | |
} | |
else { | |
printf("투입된 금액이 부족합니다.\n"); | |
return 1; | |
} | |
five = back / 500; | |
one = (back % 500) / 100; | |
printf("반환: %d원\n", back); | |
printf("오백원: %d개, 백원: %d개\n", five, one); | |
return 0; | |
} | |
/* | |
투입할 금액을 입력하세요: 1000 | |
제품의 금액을 입력하세요: 300 | |
제품의 갯수를 입력하세요: 1 | |
반환: 700원 | |
오백원: 1개, 백원: 2개 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment