Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
An employee is paid at a rate of $17.25 per hour for up to 40 regular hours worked in a week. If the employee works more than 40 hours, it is considered overtime. Any hours over 40 hours but less than or equal to 60 are paid at the overtime rate ($12.34 per hour). Any hours over 60 hours but less than equal to 80 hours are paid at the overtime rate ($14.34 per hour). Any hours over 80 hours are paid at the overtime rate ($16.00 per hour).

From the worker’s gross pay, 14% is withheld for federal income tax, 5% is withheld for state income tax. $80 is withheld to cover the insurance of the worker and 2 dependents. If the worker has more than 2 dependents, then an additional $25 is withheld per dependent for insurance. Write a program that will read in the name of the employee (use getline), number of hours worked in a week and the number of dependents as input. The program should then output the worker’s name, number of dependents, gross pay, each withholding amount, and the net take-home pay for the week.

Note the money amount displayed should be in fixed point, show point and exactly 2 significant digits after the decimal point.



Note that the ONLY INPUTS the user provides are
- The employee’s name.
- The number of hours worked in the week.
- The number of dependents.

Below are four Sample I/O


Net Paycheck Calculator

Employee's Name: John Smith
Number of Hours Worked in a Week: 43
Number of Employee's Dependents: 3

---------------------------------------------------------------------
Employee's name :John Smith
Number of Dependents :3
Hours worked :43
Overtime hours :3
Gross Income :$727.02
State Tax Withheld @ 5% :$36.35
Federal Tax Withheld @ 14% :$101.78
Worker and 2 Dependents' Insurance :$80.00
Additional Dependents' Insurance :$25.00
---------------------------------------------------------------------
Net Take Home Pay :$483.89




Net Paycheck Calculator

Employee's Name: John Smith
Number of Hours Worked in a Week: 63
Number of Employee's Dependents: 0

---------------------------------------------------------------------
Employee's name :John Smith
Number of Dependents :0
Hours worked :63
Overtime hours :23
Gross Income :$979.82
State Tax Withheld @ 5% :$48.99
Federal Tax Withheld @ 14% :$137.17
Worker and 2 Dependents' Insurance :$80.00
Additional Dependents' Insurance :$0.00
---------------------------------------------------------------------
Net Take Home Pay :$713.65





Net Paycheck Calculator

Employee's Name: John Smith
Number of Hours Worked in a Week: 35
Number of Employee's Dependents: 2

---------------------------------------------------------------------
Employee's name :John Smith
Number of Dependents :2
Hours worked :35
Overtime hours :0
Gross Income :$603.75
State Tax Withheld @ 5% :$30.19
Federal Tax Withheld @ 14% :$84.53
Worker and 2 Dependents' Insurance :$80.00
Additional Dependents' Insurance :$0.00
---------------------------------------------------------------------
Net Take Home Pay :$409.04




Net Paycheck Calculator

Employee's Name: John Smith
Number of Hours Worked in a Week: 82
Number of Employee's Dependents: 4

---------------------------------------------------------------------
Employee's name :John Smith
Number of Dependents :4
Hours worked :82
Overtime hours :42
Gross Income :$1255.60
State Tax Withheld @ 5% :$62.78
Federal Tax Withheld @ 14% :$175.78
Worker and 2 Dependents' Insurance :$80.00
Additional Dependents' Insurance :$50.00
---------------------------------------------------------------------
Net Take Home Pay :$887.04

What I have tried:

i have done this part but could'nt able to understand the next part of the question...Write a program that will read in the name of the employee (use getline), number of hours worked in a week and the number of dependents as input.
Posted
Updated 5-Oct-16 6:56am
Comments
cvogt61457 4-Oct-16 16:25pm    
Is this a programming class?
Write your first version of the program and try to get results.
First, write the basic "Hello world" program.
Second, add some functionality you need.
Third (and so on) Keep adding functionality until you have finished your task.
If you don't get the results you are looking for, we'll be happy to help work.
However, we (everyone at CodeProject) do not want to do your homework for you.

BTW: Getting paid less for working overtime???
Usually, overtime is 1.5 times your regular pay.
Just sayin.
Member 12776269 4-Oct-16 16:33pm    
#include
Member 12776269 4-Oct-16 16:35pm    
#include
[no name] 4-Oct-16 18:35pm    
Try writing a program that gets the name from the user, using the getline function, the number of hours worked in a week and the number of dependents.
cvogt61457 4-Oct-16 19:35pm    
Well, what have you tried?

Question: This is a programming class?

Get out your book and start reading with chapter 1. This will get you the basic "Hello world" program. Get this compiled and running.
Once you get this done, let me know and you will add to it.

1 solution

You must learn some basic programming skills. Begin with some input with getline in the main function, after that calculate and show the results. And define for every calculation a function.

Example funciton:
C++
const float REGULAR_PAY = 17.25; // use constants for clean code (maintainability and readability)

float calculateGrossPay( float hours) 
{
  if( hours < 0 ) return 0;//simple error handling
  if( hours < 40 ) {
    return REGULAR_PAY * hours;
  }
//your turn: handle overtime
}

Here is a tutorial for getline. As you see there are a lot of tutorials at youtube. For the output use can use printf with its formatting parameters, Take a look at the examples.

Good luck. ;-)
 
Share this answer
 
Comments
Richard MacCutchan 5-Oct-16 13:49pm    
Never use floats/doubles when calculating financial values as they are inherently inaccurate.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900