Kodewick
Start learning →
Mini challenge←→0 / 50

Profit bonus

#008Mini challenge(profit - 200000) * 0.0510 min

The bonus depends on profit, in bands: up to 100,000 gets 10%; the part from 100k to 200k gets 7.5%; 200k–400k gets 5%; 400k–600k gets 3%; 600k–1M gets 1.5%; above 1M gets 1%. For a profit of 150,000: 10000 + 50000 × 7.5% = 13750. Write bonus(profit).

Examples
bonus(80000)→8000.0
bonus(150000)→13750.0
bonus(350000)→25000.0
The functiondouble bonus(double profit)
main.c
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;
    // your code here: the three bands 200k–400k, 400k–600k and 600k–1M
    return b10 + (profit - 1000000) * 0.01;
}
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.