因此,我有一个程序,该程序使用功能来计算个人免税额和应纳税所得额。我想知道如何从函数中获取计算出的值并将变量'personalAllowance'设置为此值,以便我的代码可以正常工作。由于当前正在打印零。
float compute_taxable_income(float annualSalary, float personalAllowance)
{
float taxableIncome;
taxableIncome = (annualSalary - personalAllowance);
return taxableIncome;
}
float compute_personal_allowance ( float annualSalary )
{
float personalAllowance;
if (annualSalary <= 100000)
personalAllowance = 11850;
else if (annualSalary > 100000 && annualSalary < 123700)
{
personalAllowance = 11850 - ((annualSalary - 100000) /2);
}
else
personalAllowance = 0;
return personalAllowance;
}
int main()
{
// Variables
float annualSalary;
float taxableIncome;
float personalAllowance;
printf("what is the annualSalary \n");
scanf("%f",&annualSalary);
compute_personal_allowance (annualSalary );
compute_taxable_income( annualSalary, personalAllowance);
printf("the Taxable income is %f ", taxableIncome);
return 0;
}
答案 0 :(得分:6)
您没有为personalAllowance
或taxableIncome
分配任何内容。您需要为它们分配相关函数的返回值:
personalAllowance = compute_personal_allowance (annualSalary );
taxableIncome = compute_taxable_income( annualSalary, personalAllowance);