You are here:

C++/help with two problems


I have two problems that I'm confused with so I need help during the format for both problems.
The problems are: (1) I have to write a function called INVERSESUM, which returns the inverse sum of two real numbers, that is, 1/(x+y). I have to prompt the user for x and y and print the inverse sum.

Problem 2. I have to write a function for each of the following:
a)   federal tax deductions, 15% of salary
b)   insurance deductions, based upon a code
i.   1 indicates 5% of salary
ii.   2 indicates 8% of salary
iii.   3 indicates 0% of salary
c)   state taxes 7.5% of salary
d)   overtime pay, 1.5 more of hourly rate for hours worked over 40

The main program inputs data from a data file that contains an employee's number, hours worked, hourly rate, and insurance code. If the number of hours is greater than 40 than overtime pay is to be calculated. The main program calculates the regular pay as
  Regular Pay = Hours worked * Hourly rate
And calls all other functions as needed.

Print the employee number, hours worked, hourly rate, overtime pay (if any), all deductions, and net and gross salaries in tabular form.

Net Salary is salary after deductions
Gross Salary is salary before deductions

Hello antonio, thank you for the question.

I'm not sure why you asked me, it seems you've already written the code for these.

1. float InverseSum(float x, float y)
return 1 / (x + y);

That's all there is to the first problem. The second is a little bit more complicated. Though it's nothing more than a little bit of math.

float Federal(float salary)
return salary * .85f;

float Insurance(float salary, int code)
case 1:
return salary * .95f;

case 2:
return salary * .92f;

case 3:
return salary;

cout << code << " is not a valid code\n";


float State(float salary)
return salary * .925f;

float Overtime(float hWorked, hRate)
if(hWorked > 40.0f)
return hWorked * (hRate * 1.5f);

return hWorked * hRate;

See, that wasn't so bad. Each function returns the adjusted salary. For example: salary = Overtime(salary); would produce the money including the overtime. The rest is just merely reading in values, calling the functions, and printing the adjusted values back out to the console.

I hope this information was helpful.

- Eddie


All Answers

Answers by Expert:

Ask Experts




I can answer questions about the C++ language, object oriented design and architecture. I am knowledgable in a lot of the math that goes into programming, and am certified by I also know a good deal about graphics via OpenGL, and GUIs.


I have completed numerous games and demos created with the C++ programming language. Currently employed as a software engineer in the modeling and simulation field. I have about 7 years experience.

©2016 All rights reserved.