Link to home
Start Free TrialLog in
Avatar of nationnon
nationnon

asked on

figuring out a calculation in a programmer defined function.

Ok here's my question.  I am trying to deduct 45% from a gross pay.  I haven't the slightest idea how to insert the formula or what it's suppost to look like.  Here's what I got so far.

float calcDeductions(float numberInput)
{
      //declare and initialize variable
      float totalDeductions = 0.425;
      //calculate Deductions
      totalDeductions =


ASKER CERTIFIED SOLUTION
Avatar of jclayton
jclayton

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jclayton
jclayton

Oops, to return that value from the method call - simply do this:

float func(float input)
{
float reduction = 0.425;
return input * reduction;
}

// and is used like this
float netpay = func(grosspay);
Not quit, that calculates the deduction, not the net

i.e you have

float deduction = gross*0.425;

but you want

float net = gross*(1 - 0.425);

or

float net = gross*0.575