Search code examples
cfunctionreturnreturn-value

Why does this function return 0 even when assigned a value? (C)


Below is the code. When I test it, it keeps returning 0 for some reason.

float compute_personal_allowance ( float annualSalary ) 
{
    int pa = 0;
    if (annualSalary <= 100000)
        pa == 11850;
    else if (annualSalary > 100000)
        pa == 11850 - 1 * ((annualSalary - 100000)/2);
    return pa;
}

I test it using:

gcc -lm -std=c99 -o


Solution

  • to be complete: also the first assignment of pa is wrong:

    float compute_personal_allowance ( float annualSalary ) 
    {
        int pa = 0;
        if (annualSalary <= 100000)
            pa = 11850;
        else if (annualSalary > 100000)
            pa = 11850 - 1 * ((annualSalary - 100000)/2);
        return pa;
    }