题目:企业发放的奖金根据利润提成。
利润(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,求应发放奖金总数?
程序分析:请利用数轴来分界,定位。注意定义时需把奖金定义成长整型。
源代码如下:
# include <stdio.h>
int main(void)
{
double profit;
printf("请输入您的利润:");
scanf_s("%lf",&profit);
double bonus = 100000 * 0.01;
double bonus2 = bonus + 100000 * 0.075;
double bonus3 = bonus2 + 200000 * 0.05;
double bonus4 = bonus3 + 200000 * 0.03;
double bonus5 = bonus4 + 400000 * 0.015;
if (profit <= 100000) {
bonus = profit * 0.01;
}
else if (profit <= 200000) {
bonus = bonus + (profit-100000) * 0.075;
}
else if (profit <= 400000) {
bonus = bonus2 + (profit-200000) * 0.05;
}
else if (profit <= 600000) {
bonus = bonus3 + (profit-400000) * 0.03;
}
else if (profit <= 1000000) {
bonus = (bonus4 + profit-600000) * 0.015;
}
else if (profit > 1000000) {
bonus = bonus5 + (profit-1000000) * 0.01;
}
printf("应发奖金占总数为:%lf", bonus);
return 0;
}