下面是我编写的函数的代码,该函数在应纳税额通过时计算所得税。
本质上,该代码应根据以下内容计算该人必须支付的税额:
float compute_annual_income_tax ( float taxableIncome ) {
float t = 0;
if (taxableIncome <= 0)
t = 0 * taxableIncome;
else if (taxableIncome > 0 && taxableIncome <= 34500)
t = (taxableIncome * 0.2);
else if (taxableIncome > 34500 && taxableIncome <= 150000) {
float t2;
t2 = taxableIncome - 34500;
t = ((34500 * 0.2) + (t2 * 0.4));
}
else if (taxableIncome > 150000) {
float t2, t3;
t3 = taxableIncome - 150000;
t2 = 150000 - 34500;
t = ((34500 * 0.2) + (t2 * 0.4) + (t3 * 0.45));
}
return t;
}
使用以下代码测试代码:
gcc -lm -std = c99 -o
答案 0 :(得分:1)
您的代码按原样工作。您需要检查函数的输入以及使用输出的方式。您只需在函数的开头插入一行以打印输入,并在末尾插入一行以打印输出
float compute_annual_income_tax ( float taxableIncome ) {
float t = 0;
printf("taxable income: %f\n", taxableIncome);
...
printf("income tax: %f\n", t);
return t;
}