编程语:C 难度:中等 单个测试集评测时长限制:5秒 又到年底,兴奋的时刻到来。 公司根据销售额给员工计算奖励,计业绩为n,规则: (1) n <= 20万的部分,提成3%; (2) 20万 < n <= 50万的部分,提成2.5%; (3) n > 50万的部分,提成2%;
时间: 2023-12-03 14:47:37 浏览: 108
以下是计算员工奖励的 C 代码:
```c
#include <stdio.h>
int main() {
float performance, bonus;
printf("请输入员工的销售额(单位:万元):");
scanf("%f", &performance);
if (performance <= 0) {
printf("销售额不能为负数或零!\n");
return 0;
}
if (performance <= 20) {
bonus = performance * 0.03;
} else if (performance <= 50) {
bonus = 20 * 0.03 + (performance - 20) * 0.025;
} else {
bonus = 20 * 0.03 + 30 * 0.025 + (performance - 50) * 0.02;
}
printf("员工的奖励为:%.2f万元。\n", bonus);
return 0;
}
```
代码思路:
1. 首先,我们通过 `scanf()` 函数获取用户输入的员工销售额,存储在 `performance` 变量中。
2. 接着,我们对输入的销售额进行判断是否合法,如果小于等于 0,则输出错误提示信息并结束程序。
3. 然后,我们根据题目给出的规则计算员工奖励。使用 `if-else` 语句判断销售额属于哪个区间,分别计算出奖励金额。
4. 最后,输出员工的奖励金额,保留两位小数。