C 语言经典100例-002

企业发放的奖金根据利润提成。

  • 利润(I)低于或等于10万元时,奖金可提10%;
  • 利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可提成7.5%;
  • 20万到40万之间时,高于20万元的部分,可提成5%;
  • 40万到60万之间时高于40万元的部分,可提成3%;
  • 60万到100万之间时,高于60万元的部分,可提成1.5%;
  • 高于100万元时,超过100万元的部分按1%提成。

从键盘输入当月利润I,求应发放奖金总数?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <stdio.h>
int main()
{
    double profit, bonus;
    printf("Please enter the profit(The unit is ten thousands): \n");
    scanf("%lf", &profit);
    if(profit > 100)
    {
        bonus += (profit - 100) * 0.01;
        profit = 100;
    }
    else if(profit > 60)
    {
        bonus += (profit - 60) * 0.015;
        profit = 60;
    }
    else if(profit > 40)
    {
        bonus += (profit - 40) * 0.03;
        profit = 40;
    }
    else if(profit > 20)
    {
        bonus += (profit - 20) * 0.05;
        profit = 20;
    }
    else if(profit > 10)
    {
        bonus += (profit - 10) * 0.075;
        profit = 10;
    }
    bonus += profit * 0.1;
    printf("The bonus is(The unit is ten thousands): %.2lf\n", bonus);
    return 0;
}