题目:
企业发放的奖金根据利润提成。
- 利润低于或等于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%提成。
从键盘输入当月利润,求应发放奖金总数?
题目分析:
首先观察题目,我们会发现我们的奖金是根据企业所获得的利润进行分配的,不同区间的利润对应着不同奖金的计算方法,我首先想到了使用if-else选择语句,使得我们能够准确判断对应的的利润区间并进行相应的提成计算。
代码如下:
#include<stdio.h>
int main()
{
double profit;
double bonus_1, bonus_2, bonus_4, bonus_6, bonus_10, bonus;
//profit为利润,bonus为奖金
printf("你的利润为:");
scanf_s("%lf", &profit);
bonus_1 = 100000 * 0.1;
bonus_2 = bonus_1 + 100000 * 0.075;
bonus_4 = bonus_2 + 200000 * 0.05;
bonus_6 = bonus_4 + 200000 * 0.03;
bonus_10 = bonus_6 + 400000 * 0.015;
if (profit <= 100000) {
bonus = profit * 0.1;
}
else if (profit <= 200000) {
bonus = bonus_1 + (profit - 100000) * 0.075;
}
else if (profit <= 400000) {
bonus = bonus_2 + (profit - 200000) * 0.05;
}
else if (profit <= 600000) {
bonus = bonus_4 + (profit - 400000) * 0.03;
}
else if (profit <= 1000000) {
bonus = bonus_6 + (profit - 600000) * 0.015;
}
else if (profit > 1000000) {
bonus = bonus_10 + (profit - 1000000) * 0.01;
}
printf("经过公司计算,您的提成应为:%lf", bonus);
printf("\n");
return 0;
}
计算结果:
代码分析:
使用if—else进行利润区间的划分,再进行计算即可。
备注:
由于不同版本的编译器问题,如果发现无法运行,请将scanf_s改为scanf,本人使用VS 2022版本
2022年7月于福建
——暮炊雪