C Exercise Example 2
Title:Bonuses distributed by enterprises are based on profit commissions.
- When profit (I) is less than or equal to 100,000 yuan, the bonus can be 10%;
- When profit is higher than 100,000 yuan and lower than 200,000 yuan, the portion below 100,000 yuan is commissioned at 10%, and the portion above 100,000 yuan can be commissioned at 7.5%;
- When it is between 200,000 and 400,000 yuan, the portion above 200,000 yuan can be commissioned at 5%;
- When it is between 400,000 and 600,000 yuan, the portion above 400,000 yuan can be commissioned at 3%;
- When it is between 600,000 and 1,000,000 yuan, the portion above 600,000 yuan can be commissioned at 1.5%;
- When it is higher than 1,000,000 yuan, the portion exceeding 1,000,000 yuan is commissioned at 1%.
Input the current month's profit I from the keyboard, and find the total bonus to be distributed?
Program analysis:Please use the number line to demarcate and locate. Note that when defining, the bonus needs to be defined as a double-precision floating-point (double) type.
Example
#include<stdio.h>
int main()
{
double i;
double bonus1,bonus2,bonus4,bonus6,bonus10,bonus;
printf("Your net profit is:\n");
scanf("%lf",&i);
bonus1=100000*0.1;
bonus2=bonus1+100000*0.075;
bonus4=bonus2+200000*0.05;
bonus6=bonus4+200000*0.03;
bonus10=bonus6+400000*0.015;
if(i<=100000) {
bonus=i*0.1;
} else if(i<=200000) {
bonus=bonus1+(i-100000)*0.075;
} else if(i<=400000) {
bonus=bonus2+(i-200000)*0.05;
} else if(i<=600000) {
bonus=bonus4+(i-400000)*0.03;
} else if(i<=1000000) {
bonus=bonus6+(i-600000)*0.015;
} else if(i>1000000) {
bonus=bonus10+(i-1000000)*0.01;
}
printf("The commission is: bonus=%lf",bonus);
printf("\n");
}
The output of the above example is:
你的净利润是: 120000 提成为:bonus=11500.000000other extensions