Solved

# figuring out a calculation in a programmer defined function.

Posted on 2000-03-07
191 Views
Last Modified: 2010-04-02
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 =

0
Question by:nationnon
• 2
3 Comments

Accepted Solution

jclayton earned 35 total points
ID: 2591011
totalDeductions = numberInput * 0.425;

0

Expert Comment

ID: 2591015
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);
0

LVL 22

Expert Comment

ID: 2591691
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
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

### Suggested Solutions

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

#### 821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.