#include <stdio.h>
//简单理解版
int main()
{
double x,money;
scanf("%lf",&x);
if(x<=100000)
money=x*0.1;
else
{
if(x<=200000)
money = 100000*0.1+(x-100000)*0.075;
else
{
if(x<=400000)
money=100000*0.1+100000*0.075+(x-200000)*0.05;
else
{
if(x<=600000)
money=100000*0.1+100000*0.075+200000*0.05+(x-400000)*0.03;
else
{
if(x<=1000000)
money=100000*0.1+100000*0.075+200000*0.05+200000*0.03+(x-600000)*0.015;
else
money=100000*0.1+100000*0.075+200000*0.05+200000*0.03+400000*0.015+(x-1000000)*0.01;
}
}
}
}
printf("money=%f",money);
return 0;
}
****************************************************************************************************************************************************************************
#include <stdio.h>
//精简后代码
int main()
{
double x,finalbonus,bonus1,bonus2,bonus3,bonus4,bonus5;
scanf("%lf",&x);
bonus1=100000*0.1;
bonus2=bonus1+100000*0.075;
bonus3=bonus3+200000*0.05;
bonus4=bonus4+200000*0.03;
bonus5=bonus5+400000*0.015;
if (x<=100000)
finalbonus=x*0.1;
else
{
if(x<=200000)
finalbonus=bonus1+(x-100000)*0.075;
else
{
if(x<=400000)
finalbonus=bonus2+(x-200000)*0.05;
else
{
if(x<=600000)
finalbonus=bonus3+(x-400000)*0.03;
else
{
if(x<=1000000)
finalbonus=bonus4+(x-600000)*0.015;
else
finalbonus=bonus5+(x-1000000)*0.001;
}
}
}
}
printf("奖金%6.1f",finalbonus);
return 0;
}
*****************************************************************************************************************************************************************************************
//switch方法
#include <stdio.h>
int main()
{
int i;
double bonus,bon1,bon2,bon4,bon6,bon10;
int branch;
bon1=100000*0.1;
bon2=bon1+100000*0.075;
bon4=bon2+200000*0.05;
bon6=bon4+200000*0.03;
bon10=bon6+400000*0.015;
printf("请输入利润i:");
scanf("%d",&i);
branch=i/100000;
if(branch>10) branch = 10;
switch(branch)
{
case 0:bonus=i*0.1;break;
case 1:bonus=bon1+(i-100000)*0.075;break;
case 2:
case 3:bonus=bon2+(i-200000)*0.05;break;
case 4:
case 5:bonus=bon4+(i-400000)*0.03;break;
case 6:
case 7:
case 8:
case 9:bonus=bon6+(i-600000)*0.015;break;
case 10:bonus=bon10+(i-1000000)*0.01;break;
}
printf("%f",bonus);
return 0;
}