用C语言编写一个个税计算器,用户输入为应发工资薪金所得扣除五险一金后的金额,输出应缴税款和实发工资,结果保留小数点后两位。当输入数字小于0时,输出“error”
时间: 2024-05-18 17:15:52 浏览: 113
好的,这是一个很好的问题,以下是用C语言编写的个税计算器的代码:
```c
#include<stdio.h>
int main()
{
float salary, tax, real_salary, insurance, threshold;
printf("请输入您的应发工资:");
scanf("%f", &salary);
if (salary < 0) {
printf("error");
return 0;
}
printf("请输入五险一金扣除的金额:");
scanf("%f", &insurance);
threshold = 5000; // 免征额为5000元
salary -= insurance;
if (salary <= threshold) {
tax = 0;
} else if (salary <= 8000) {
tax = (salary - threshold) * 0.03;
} else if (salary <= 17000) {
tax = (salary - threshold) * 0.1 - 210;
} else if (salary <= 30000) {
tax = (salary - threshold) * 0.2 - 1410;
} else if (salary <= 40000) {
tax = (salary - threshold) * 0.25 - 2660;
} else if (salary <= 60000) {
tax = (salary - threshold) * 0.3 - 4410;
} else if (salary <= 80000) {
tax = (salary - threshold) * 0.35 - 7160;
} else {
tax = (salary - threshold) * 0.45 - 15160;
}
real_salary = salary - tax;
printf("应缴税款为:%.2f\n", tax);
printf("实发工资为:%.2f\n", real_salary);
return 0;
}
```
上面的代码中,我们先定义了应发工资、应缴税款、实发工资、五险一金和免征额等变量。然后让用户输入应发工资和五险一金扣除的金额,如果应发工资小于0,输出“error”,程序结束。否则,将五险一金扣除后的金额作为应发工资进行计算。根据个人所得税的计算方法,我们将每个税率阶段的应缴税款计算出来,并将实发工资计算出来。最后,用printf函数输出应缴税款和实发工资,结果保留小数点后两位。
希望能够帮到你!
阅读全文