Aimee Boyle
Aimee Boyle

Reputation: 11

how do i use a value returned from a function in c

So I have a program that uses functions to calculate the personal allowance and the taxable income. I would like to know how to take the calculated value from my function and set the variable 'personalAllowance' to this value so my code will work correctly. As it's currently printing zero.

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;
}

Upvotes: 0

Views: 63

Answers (1)

dbush
dbush

Reputation: 223699

You're not assigning anything to personalAllowance or taxableIncome. You need to assign the return value of the relevant functions to them:

personalAllowance = compute_personal_allowance (annualSalary );
taxableIncome = compute_taxable_income( annualSalary, personalAllowance);

Upvotes: 6

Related Questions