#include <stdio.h>
int main()
{
int profit, bonus = 0; //profit bonus
scanf("%d", &profit); //516000 0
if (profit > 1000000) //
{ //
bonus += (profit - 1000000) * 0.01; //
profit = 1000000; //
} //
if (profit > 600000) //
{ //
bonus += (profit - 600000) * 0.015; //
profit = 600000; //
} //
if (profit > 400000) //
{ //
bonus += (profit - 400000) * 0.03; // 3480
profit = 400000; //400000
} //
if (profit > 200000) //
{ //
bonus += (profit - 200000) * 0.05; // 13480
profit = 200000; //200000
} //
if (profit > 100000) //
{ //
bonus += (profit - 100000) * 0.075; // 20980
profit = 100000; //100000
} //
if (profit <= 100000) //
{ //
bonus += profit * 0.1; // 30980
profit = 0; //0
} //
printf("%d\n", bonus);
return 0;
}
中间的if改成 else if
除了第一个if之外,后面的if全部改成else if
否则前面计算都白做了,能匹配后面的if就又继续执行后面的语句
条件都满足就会重新计算,第一个if后边都换成else if