Kodewick
Commencer à apprendre →
Mini-défi←→0 / 50

Prime sur le bénéfice

#008Mini-défi(profit - 200000) * 0.0510 min

La prime se calcule par tranches de bénéfice : jusqu’à 100 000, 10 % ; de 100 000 à 200 000, 7,5 % ; de 200 000 à 400 000, 5 % ; de 400 000 à 600 000, 3 % ; de 600 000 à 1 000 000, 1,5 % ; au-delà, 1 %. Ex. pour 150 000 : 10000 + 50000 × 7,5 % = 13750. Écris bonus(profit).

Exemples
bonus(80000)→8000.0
bonus(150000)→13750.0
bonus(350000)→25000.0
La fonctiondouble 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;
    // ton code ici: les tranches 200 000–400 000, 400 000–600 000 et 600 000–1 000 000
    return b10 + (profit - 1000000) * 0.01;
}
Ctrl + Entrée lance aussi le code
Résultat

Exécuter teste les exemples. Quand ils sont bons, appuie sur Envoyer.