用C语言的选择结构程序写一个奖金提成,并加上注释
时间: 2024-05-19 12:15:54 浏览: 10
#include <stdio.h>
int main() {
float profit; // 定义利润变量
float bonus; // 定义奖金变量
printf("请输入利润:");
scanf("%f", &profit); // 输入利润
if (profit <= 0) { // 判断利润是否小于等于0
printf("输入有误!\n");
}
else if (profit <= 100000) { // 判断利润是否小于等于100000
bonus = profit * 0.1; // 计算奖金
printf("奖金为:%f\n", bonus); // 输出奖金
}
else if (profit <= 200000) { // 判断利润是否小于等于200000
bonus = 100000 * 0.1 + (profit - 100000) * 0.075; // 计算奖金
printf("奖金为:%f\n", bonus); // 输出奖金
}
else if (profit <= 400000) { // 判断利润是否小于等于400000
bonus = 100000 * 0.1 + 100000 * 0.075 + (profit - 200000) * 0.05; // 计算奖金
printf("奖金为:%f\n", bonus); // 输出奖金
}
else if (profit <= 600000) { // 判断利润是否小于等于600000
bonus = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + (profit - 400000) * 0.03; // 计算奖金
printf("奖金为:%f\n", bonus); // 输出奖金
}
else if (profit <= 1000000) { // 判断利润是否小于等于1000000
bonus = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + 200000 * 0.03 + (profit - 600000) * 0.015; // 计算奖金
printf("奖金为:%f\n", bonus); // 输出奖金
}
else { // 判断利润是否大于1000000
bonus = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + 200000 * 0.03 + 400000 * 0.015 + (profit - 1000000) * 0.01; // 计算奖金
printf("奖金为:%f\n", bonus); // 输出奖金
}
return 0;
}