Section 2.3 of "Algorithm Notes"-C/C++ Quick Start -> Select Structure Exercises 4-10-1 Bonus Calculation

Exercise 4-10-1 Bonus Calculation

Topic description
The bonus issued by a company is based on the profit commission. When the profit I is less than or equal to 100,000, the bonus can be increased by 10%; when the profit is higher than 100,000 yuan, and when the profit is less than 200,000 yuan (100000<I<=200000), the part below 100,000 yuan is still subject to a 10% commission, which is higher than 100,000 The partial commission rate of RMB is 7.5%; when 200000<I<=400000, the part below 200,000 yuan will still be commissioned according to the above method (the same below), and the part above 200,000 yuan will be commissioned at 5%; 400000<I<=600000 When it is RMB, the part higher than 400,000 RMB is subject to 3% commission; when 600000<I<=1000000, the part higher than 600,000 RMB is subject to 1.5% commission; when I>1000000 yuan, the part exceeding 1000000 yuan is subject to 1% commission.
Output the profit I of the current month from the keyboard, find the number of bonuses that should be issued, and the bonuses are accurate to the point.
It is required to be implemented with an if statement.
Input
Enterprise profit, decimal, double-precision double type
output The
number of bonuses to be issued, keep 2 decimal places, and wrap at the end.
Sample input Copy
1050
Sample output Copy
105.00

#include <stdio.h>

int main() {
    
    
    double profit, bonus;
    scanf("%lf", &profit);
    if (profit <= 100000)
        bonus = profit * 0.1;
    else if (profit <= 200000)
        bonus = (profit - 100000) * 0.075 + 10000;
    else if (profit <= 400000)
        bonus = (profit - 200000) * 0.05 + 7500 + 10000;
    else if (profit <= 600000)
        bonus = (profit - 400000) * 0.03 + 10000 + 7500 + 10000;
    else if (profit <= 1000000)
        bonus = (profit - 600000) * 0.015 + 6000 + 10000 + 7500 + 10000;
    else
        bonus = (profit - 1000000) * 0.01 + 3000 + 6000 + 10000 + 7500 + 10000;
    printf("%.2f", bonus);
    return 0;
}

Guess you like

Origin blog.csdn.net/DoMoreSpeakLess/article/details/109733288