c语言 请编写一个个税计算器,用户输入为应发工资薪金所得扣除五险一金后的金额,输出应缴税款和实发工资,结果保留小数点后两位。当输入数字小于0时,输出“error”
时间: 2024-03-08 07:50:34 浏览: 195
税率计算器(C语言)
好的,我可以帮你编写一个C语言的个税计算器程序。
以下是程序代码:
```c
#include <stdio.h>
int main() {
float salary; // 应发工资
float social_security = 0; // 五险一金
float taxable_income; // 应纳税所得额
float tax; // 应缴税款
float net_income; // 实发工资
printf("请输入应发工资金额(扣除五险一金后):");
scanf("%f", &salary);
if (salary < 0) {
printf("error\n");
return 0;
}
if (salary <= 3500) {
taxable_income = 0;
} else {
taxable_income = salary - 3500 - social_security;
}
if (taxable_income <= 0) {
tax = 0;
} else if (taxable_income <= 1500) {
tax = taxable_income * 0.03;
} else if (taxable_income <= 4500) {
tax = taxable_income * 0.1 - 105;
} else if (taxable_income <= 9000) {
tax = taxable_income * 0.2 - 555;
} else if (taxable_income <= 35000) {
tax = taxable_income * 0.25 - 1005;
} else if (taxable_income <= 55000) {
tax = taxable_income * 0.3 - 2755;
} else if (taxable_income <= 80000) {
tax = taxable_income * 0.35 - 5505;
} else {
tax = taxable_income * 0.45 - 13505;
}
net_income = salary - social_security - tax;
printf("应缴税款为:%.2f元\n", tax);
printf("实发工资为:%.2f元\n", net_income);
return 0;
}
```
程序运行后,会要求用户输入应发工资金额(扣除五险一金后),然后会进行个税计算,并输出应缴税款和实发工资。
注意,如果用户输入的数字小于0,程序会输出"error"。
阅读全文