Experiment 3-11 Calculate the oil fee (15 points)

The current 90gasoline is 6.95RMB/liter, 93gasoline is 7.44RMB/liter, 97and gasoline is 7.93RMB/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:

Insert picture description here

Problem-solving ideas:

Maybe (absolutely) it can be optimized~

Guess you like

Origin blog.csdn.net/weixin_43862765/article/details/114457474