所以我有一个程序,使用函数来计算个人津贴和应税收入。我想知道如何从我的函数中获取计算值,并将变量“personalallowment”设置为此值,以便我的代码能够正常工作。因为它正在打印零。
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;
}
最佳答案
您没有为personalAllowance
或taxableIncome
分配任何内容。您需要将相关函数的返回值分配给它们:
personalAllowance = compute_personal_allowance (annualSalary );
taxableIncome = compute_taxable_income( annualSalary, personalAllowance);