728x90
시간대별 통화요금 계산기 예제코드: if, else, char
포스트 난이도: HOO_Junior
# Example Codes
#include <stdio.h>
#include <stdlib.h>
int main()
{
int min, dayOrNight;
float rCharge, pCharge;
char serviceCode;
printf("The rates are computed as follows: Regular service: $10.00 plus first 50 minutes are free.\n");
printf("Charges for over 50 minutes are $0.20 per minute, Premium service: $25.00 plus. \n");
printf("Enter your service code:");
scanf("%c",&serviceCode);
printf("Enter your number of minutes for using service:");
scanf("%d", &min);
if(serviceCode == 'r' || serviceCode == 'R'){
if(min>50){
rCharge = (min-50)*0.20 +10.00;
printf("Charge: $%.2f \n", rCharge);
}
else{
rCharge=10.00;
printf("Charge: $%.2f\n", rCharge);
}
}
else if(serviceCode=='p'|| serviceCode=='P'){
printf("Are you using the service day(1) or night(2):");
scanf("%d",&dayOrNight);
if(dayOrNight==1)
{
if(min>75){
pCharge = (min-75)*0.1 + 25;
printf("Charge: $%.2f\n", pCharge);
}
else{
pCharge = 25;
printf("Charge: $%.2f\n", pCharge);
}
}
else if (dayOrNight==2){
if(min>100){
pCharge = (min-100)*0.05 + 25;
printf("Charge: $%.2f\n", pCharge);
}
else{
pCharge = 25;
printf("Charge: $%.2f\n", pCharge);
}
}
else{
printf("You typed the wrong day or night, please try it again.\n");
}
}
else
printf("You typed the wrong code, please try it again.\n");
printf("Coded by HOO.\n");
return 0;
}
The rates are computed as follows: Regular service: $10.00 plus first 50 minutes are free.
Charges for over 50 minutes are $0.20 per minute, Premium service: $25.00 plus.
Enter your service code:r
Enter your number of minutes for using service:300
Charge: $60.00
Coded by HOO.
The rates are computed as follows: Regular service: $10.00 plus first 50 minutes are free.
Charges for over 50 minutes are $0.20 per minute, Premium service: $25.00 plus.
Enter your service code:p
Enter your number of minutes for using service:95
Are you using the service day(1) or night(2):1
Charge: $27.00
Coded by HOO.
728x90
'C and C++ > C and C++ Examples' 카테고리의 다른 글
[C Examples] 입력된 숫자의 각 자리수를 더하고 3과 9로 나누어지는지 살펴보는 예제코드: do while(), if() (0) | 2023.03.23 |
---|---|
[C Examples] 입력한 온도 값에 따라 온도 상태 구분하기 예제 코드: if(), else if(), while() (0) | 2023.03.22 |
[C Examples] 세금 계산기 예제코드: if, else if (0) | 2023.02.19 |
[C Examples] 24시간을 12시간 표기로 바꾸기 예제코드: if(), else (0) | 2023.02.18 |
[C Examples] GPA 계산기 예제코드: if(), else if() (0) | 2023.02.17 |
댓글