我已經得到了這段代碼,它可以計算員工工資的月度稅。當我運行它時,似乎一切正常,直到if子句中的點。C算法不評估
如果我提供basicSalary爲50000和所有其他的輸入值爲0,monthlyTax圖來自零點的時候應該是4000左右。
任何人可以解釋我爲什麼發生這種情況?
#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;
}
這對被看中並使用'15/100',而不是更 「接地」'0.15'; - ) – dasblinkenlight 2013-02-15 18:08:00
而在C中,它應該是'int main(void)',因爲'()'在參數聲明中不等於'(void)'。哦,請停止在行首開始印刷換行的疾病;它們屬於打印行的末尾。 – Jens 2013-02-15 18:09:47
謝謝你們倆! :) @dasblinkenlight - yup,太有趣了:P – Hirvesh 2013-02-15 18:11:34