獎金按利潤(元)分段算: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;
}
寫好了先點「執行」試試示例,沒問題再點「提交」。