企业发放的奖金根据利润提成,
利润I低于等于十万元的,奖金可提成10%;
利润高于十万小于等于二十万元的,低于十万元的部分按10%提成,高于十万元的部分,可提成7.5%;
高于二十万元小于等于四十万元时,低于或等于二十万元的部分人按上述办法提成(下同)高于二十万元的部分按5%提成;
高于四十万元到小于等于六十万元时,高于四十万元的部分按3%提成;
高于六十万元到小于等于一百万元时,高于六十万的部分按1.5%提成;
高于一百万元超过一百万元的部分按1%提成
从键盘输入当月利润I,求应发放奖金总数。
要求用
(1)if语句编程序
(2)用switch语句编程序
#include <stdio.h>
int main() {
double bonus, profit;
printf("请输入当月利润:");
scanf("%lf", &profit);
if (profit <= 100000) {
bonus = profit * 0.1;
} else if (profit <= 200000) {
bonus = 100000 * 0.1 + (profit - 100000) * 0.075;
} else if (profit <= 400000) {
bonus = 100000 * 0.1 + 100000 * 0.075 + (profit - 200000) * 0.05;
} else if (profit <= 600000) {
bonus = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + (profit - 400000) * 0.03;
} else if (profit <= 1000000) {
bonus = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + 200000 * 0.03 + (profit - 600000) * 0.015;
} else {
bonus = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + 200000 * 0.03 + 400000 * 0.015 + (profit - 1000000) * 0.01;
}
printf("应发放奖金总数:%.2lf\n", bonus);
return 0;
}
#include <stdio.h>
int main() {
double bonus = 0, profit;
printf("请输入当月利润:");
scanf("%lf", &profit);
switch ((int)(profit / 100000)) {
case 0:
bonus = profit * 0.1;
break;
case 1:
bonus = 100000 * 0.1 + (profit - 100000) * 0.075;
break;
case 2:
case 3:
bonus = 100000 * 0.1 + 100000 * 0.075 + (profit - 200000) * 0.05;
break;
case 4:
case 5:
bonus = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + (profit - 400000) * 0.03;
break;
case 6:
case 7:
case 8:
case 9:
bonus = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + 200000 * 0.03 + (profit - 600000) * 0.015;
break;
default:
bonus = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + 200000 * 0.03 + 400000 * 0.015 + (profit - 1000000) * 0.01;
break;
}
printf("应发放奖金总数:%.2lf\n", bonus);
return 0;
}
代码说明:
(1) 用if语句
- 提示用户输入当月利润。
- 使用
if-else
结构根据利润范围计算奖金。 - 输出奖金总数。
代码说明:
(2) 用switch语句
- 提示用户输入当月利润。
- 使用
switch
语句根据利润范围计算奖金。 - 输出奖金总数。
- 注意:
switch
语句根据利润除以10万后取整来判断范围,并结合case
结构计算奖金。