我有这段代码可以计算员工工资的月税。当我运行它时,一切似乎都运行良好,直到 if 子句中的点。
如果我将 basicSalary 提供为 50000 并将所有其他输入值提供为 0,那么当应在 4000 左右时,monthlyTax 数字会变为零。
谁能解释我为什么会这样?
#include <stdio.h>
int main()
{
int basicSalary, allowances, transportAllowance, numberOfDependants, deduction;
float monthlyTax, income;
printf("Enter Basic Salary Amount: ");
scanf("%d", &basicSalary);
printf("\nEnter Allowances Amount: ");
scanf("%d", &allowances);
printf("\nEnter transportAllowance Amount: ");
scanf("%d", &transportAllowance);
printf("\nEnter Number Of Dependants: ");
scanf("%d", &numberOfDependants);
switch (numberOfDependants)
{
case 0:
deduction = 215000;
break;
case 1:
deduction = 325000;
break;
case 2:
deduction = 415000;
break;
case 3:
deduction = 475000;
break;
default:
printf("Number Of Dependants Can Only Be Between 0 - 3, Enter A Proper Value.");
return 1;
}
income = basicSalary * 13 + allowances + (transportAllowance - 6800) * 12 - deduction;
if (income < 500000)
{
monthlyTax = ((15/100) * (income/12));
}
else
{
monthlyTax = ((15/100) * (500000/12)) + ((30/100) * ((income-500000)/12));
}
monthlyTax = monthlyTax/12;
printf("\nMothly Tax Amount is %f", monthlyTax);
getch();
return 0;
}