The current 90
gasoline is 6.95
RMB/liter, 93
gasoline is 7.44
RMB/liter, 97
and gasoline is 7.93
RMB/liter. To attract customers, an automatic gas station launched a "self-service" and "assistance service" two service levels were available 5%
and 3%
discounts.
This question requires writing a program to calculate and output the payables based on the input customer’s fuel amount a
, gasoline type b(90、93或97)
and service type c(m - 自助,e - 协助)
.
Input format:
Enter two integers and one character in one line, which represent the customer's fuel amount a
, gasoline type, b(90、93或97)
and service type c(m - 自助,e - 协助)
.
Output format:
Output the payable amount in one line, keeping 2 decimal places.
Input sample:
40 97 m
Sample output:
301.34
Code:
# include <stdio.h>
# include <stdlib.h>
int main() {
int oil,variety;
char service;
double pay;
scanf("%d %d %c",&oil,&variety,&service);
if (service == 'm') {
if (variety == 90) {
pay = oil * 6.95 * (1 - 0.05);
}else if (variety == 93) {
pay = oil * 7.44 * (1 - 0.05);
}else {
pay = oil * 7.93 * (1 - 0.05);
}
}else {
if (variety == 90) {
pay = oil * 6.95 * (1 - 0.03);
}else if (variety == 93) {
pay = oil * 7.44 * (1 - 0.03);
}else {
pay = oil * 7.93 * (1 - 0.03);
}
}
printf("%.2lf",pay);
return 0;
}
Submit screenshot:
Problem-solving ideas:
Maybe (absolutely) it can be optimized~