SHARE
HELP

To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

Authors:
Walter Savitch ,kenrick Mock
Chapter:
C++ Basics
Exercise:
Programming Projects
Question:6 | ISBN:9780132846813 | Edition: 5

### Question

An employee is paid at a rate of \$16.78 per hour for regular hours worked in a week. Any hours over that are paid at the overtime rate of one and one-half times that. From the worker’s gross pay, 6% is withheld for Social Security tax, 14% is withheld for federal income tax, 5% is withheld for state income tax, and \$10 per week is withheld for union dues. If the worker has three or more dependents, then an additional \$35 is withheld to cover the extra cost of health insurance beyond what the employer pays. Write a program that will read in the number of hours worked in a week and the number of dependents as input and that will then output the worker’s gross pay, each withholding amount, and the net take-home pay for the week.

``````//Include header files for running C++ program
#include<iostream>
using namespace std;
//main function
int main()
{
//Variables declaration
int numHoursWorked;
int numOfDependents;
double workersGrossPay;
char programerChoice;
//do-while loop repeats the program multiple times
//as per programmer choice
do
{
// Read in the number of hours worked in a week
//and the number of dependents as input
cout<<" Please enter number of hours worked per week: ";
cin>>numHoursWorked;
cout<<"Please enter number of dependents : ";
cin>>numOfDependents;

//Calculate grosspay of the worker as per given question
workersGrossPay =  numHoursWorked>40?((40 * 16.78)
+  (numHoursWorked-40)*(16.78*1.5)): (numHoursWorked*16.78);
cout<<workersGrossPay<<endl;

//Output the worker’s gross pay, each withholding amount,
// and the net take-home pay for the week
cout<<" Worker\'s gross pay :";
cout<<" Withhold amount  for state income tax= "
<<(.05 * workersGrossPay)<<"\n";
cout<<" Withhold amount for Social security tax = "
<<(.06* workersGrossPay)<<"\n";
cout<<" Withhold amount  for federal income tax = "
<<(.14* workersGrossPay)<<"\n";
cout<<" Withhold amount  for union dues= \$ 10 "<<"\n";
if(numOfDependents >= 3)
{
cout<<" Withhold amount  for insurance cost \$35\n";
workersGrossPay -= 35;
}
cout<<" Net amount take-home pay for the week  ";
cout<<(workersGrossPay*(1-0.06 - 0.05-0.14) - 10)<<endl;
cout<<"Press 'Y or y' for repeat again, otherwise press any character: ";
cin>>programerChoice;
}while(programerChoice =='y' || programerChoice =='Y');

}
``````

Output 1 of the program code:

``````Please enter number of hours worked per week: 40
Please enter number of dependents : 2
671.2
Worker's gross pay : Withhold amount  for state income tax= 33.56
Withhold amount for Social security tax = 40.272
Withhold amount  for federal income tax = 93.968
Withhold amount  for union dues= \$ 10
Net amount take-home pay for the week  493.4
Press 'Y or y' for repeat again, otherwise press any character: y
Please enter number of hours worked per week: 54
Please enter number of dependents : 4
1023.58
Worker's gross pay : Withhold amount  for state income tax= 51.179
Withhold amount for Social security tax = 61.4148
Withhold amount  for federal income tax = 143.301
Withhold amount  for union dues= \$ 10
Withhold amount  for insurance cost \$35
Net amount take-home pay for the week  731.435
Press 'Y or y' for repeat again, otherwise press any character: n``````

Output 2 of the program code:

``````Please enter number of hours worked per week: 48
Please enter number of dependents : 4
872.56
Worker's gross pay : Withhold amount  for state income tax= 43.628
Withhold amount for Social security tax = 52.3536
Withhold amount  for federal income tax = 122.158
Withhold amount  for union dues= \$ 10
Withhold amount  for insurance cost \$35
Net amount take-home pay for the week  618.17
Press 'Y or y' for repeat again, otherwise press any character: n ``````

### Discussions

Post the discussion to improve the above solution.