奖金按利润(元)分段算:10 万以内提 10%;10–20 万的部分提 7.5%;20–40 万的部分 5%;40–60 万的部分 3%;60–100 万的部分 1.5%;超过 100 万的部分 1%。比如利润 15 万:10000 + 50000 × 7.5% = 13750。写 bonus(profit)。
bonus(80000)→8000.0bonus(150000)→13750.0bonus(350000)→25000.0double bonus(double profit)double bonus(double profit) {
double b1 = 100000 * 0.1;
double b2 = b1 + 100000 * 0.075;
double b4 = b2 + 200000 * 0.05;
double b6 = b4 + 200000 * 0.03;
double b10 = b6 + 400000 * 0.015;
if (profit <= 100000) return profit * 0.1;
if (profit <= 200000) return b1 + (profit - 100000) * 0.075;
// 在这里写:20–40 万、40–60 万、60–100 万这三档
return b10 + (profit - 1000000) * 0.01;
}
写好了先点「运行」试试示例,没问题再点「提交」。