《算法笔记》2.3小节——C/C++快速入门->选择结构 习题4-10-1 奖金计算

习题4-10-1 奖金计算

题目描述
某企业发放的奖金根据利润提成。利润I低于或等于100000时,奖金可提10%;利润高于100000元,低于200000元(100000<I<=200000)时,低于100000元的部分仍按10%提成,高于100000元的部分提成比例为7.5%;200000<I<=400000时,低于200000元的部分仍按上述方法提成(下同),高于200000元的部分按5%提成;400000<I<=600000元时,高于400000元的部分按3%提成;600000<I<=1000000时,高于600000元的部分按1.5%提成;I>1000000元时,超过1000000元的部分按1%提成。
从键盘输出当月利润I,求应发奖金数,奖金精确到分。
要求用if语句实现。
输入
企业利润,小数,双精度double类型
输出
应发奖金数,保留2位小数,末尾换行。
样例输入 Copy
1050
样例输出 Copy
105.00

#include <stdio.h>

int main() {
    
    
    double profit, bonus;
    scanf("%lf", &profit);
    if (profit <= 100000)
        bonus = profit * 0.1;
    else if (profit <= 200000)
        bonus = (profit - 100000) * 0.075 + 10000;
    else if (profit <= 400000)
        bonus = (profit - 200000) * 0.05 + 7500 + 10000;
    else if (profit <= 600000)
        bonus = (profit - 400000) * 0.03 + 10000 + 7500 + 10000;
    else if (profit <= 1000000)
        bonus = (profit - 600000) * 0.015 + 6000 + 10000 + 7500 + 10000;
    else
        bonus = (profit - 1000000) * 0.01 + 3000 + 6000 + 10000 + 7500 + 10000;
    printf("%.2f", bonus);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/DoMoreSpeakLess/article/details/109733288