Program to compute gross and net pay with overtime Modify as
Program to compute gross and net pay with overtime
Modify assignment #3 to include overtime. If the employee works more than 35 hours he is paid at time-and-a-half for the hours that exceeds 35 and regular pay otherwise. Your output must show on separate lines. All dollar amount must be displayed with a dollar $ symbol preceding it and rounded to 2 decimal places. Run your program for a)hours=48 and hourly rate = $8.95 b) hours=31 and hourly rate = $8.95. Your output must show the following information for each RUN.
1) The number of hours worked
2) The regular pay
3) The overtime pay
4) The gross pay
5) The net pay
6) The amount of state tax
7) The amount of federal tax
Sample RUN #1:
What is the number of hours worked? 48
What is the rate of pay? 8.95
The regular pay is :$???.??
The over-time pay is: $???.??
The gross pay is : $???.??
The net pay is : $???.??
The state tax is : $???.??
The federal tax is: $???.??
Sample RUN #2:
What is the number of hours worked? 31
What is the rate of pay? 8.95
The regular pay is :$???.??
The over-time pay is: $0
The gross pay is : $???.??
The net pay is : $???.??
The state tax is : $???.??
The federal tax is: $???.??
This is what I have. I believe i did the one without overtime correct.
// Program to compute gross and net pay with overtime
#include <iostream>
#include <iomanip> // For Setprecision (2) when calculating StateTax and FederalTax
#include <cmath>
#include <string.h>
using namespace std;
int main()
{
double NetPayAmt ;
double GrossPay ;
double StateTaxAmt=0.0825; // this state declares StateTaxAmt as a double and set it equal to the decimal value 0.0825n
double FederalTaxAmt=0.175 ; // this state declares FederalTaxAmt as a double and set it equal to the decimal value 0.175n
double regularpay ; // this state declares regularpay as a double and set it equal to the decimal value
double overtimepay ; // this state declares overtimepay as a double and set it equal to the decimal value if regularpay is greater thaan 40 HoursWorked
double overtimehours ; // this state declares overtimehours as a double and set it equal to the decimal vaule
double regularhours; // this state declares regularhours as a double and set it equal to the decimal vaule
double regularpayrate;
// read the input values
cout << \"Enter the regularpay Rate?: \";
cin >> regularpayrate ;
cout << \"Enter the overtimehours?:\" ;
cin >> overtimehours ;
cout << \"Enter the regular hours\" ;
cin >> regularhours ;
// compute the Grosspay, StateTaxAmt, FederalTaxAmt, NetPayAmt, regularpay, overtimepay ,overtimehours
regularpay = regularpayrate * regularhours ;
GrossPay = regularpay + overtimepay ;
StateTaxAmt = GrossPay * 0.0825 ; // this state declares StateTaxRate as a double and set it equal to the decimal value 0.0825n
FederalTaxAmt = GrossPay * 0.175 ; // this state declares FederalTaxRate as a double and set it equal to the decimal value 0.175n
NetPayAmt = GrossPay - FederalTaxAmt - StateTaxAmt ;
// display GrossPay , StateTaxAmt , FederalTaxAmt , NetPayAmt, regulatpay, overtimepay, overtimehours
cout.setf(ios::fixed) ; // These lines force currency format in output to 2 decimal pts
cout.setf(ios::showpoint);
cout.precision(2);
cout << \" The regular pay is : $\" << regularpay << endl ;
cout << \" The overtimepay is: $\" << overtimepay << endl ;
cout<<\" The is GrossPay: $\" << GrossPay <<endl;
cout<<\" The is NetPayAmt: $\" << NetPayAmt <<endl;
cout<<\" The is StateTaxAmt: $\" << StateTaxAmt <<endl;
cout<<\" The is FederaltTaxAmt: $\" << FederalTaxAmt <<endl;
}
Solution
#include <iostream>
#include <iomanip> // For Setprecision (2) when calculating StateTax and FederalTax
#include <cmath>
#include <string.h>
using namespace std;
int main()
{
double NetPayAmt ;
double GrossPay ;
double StateTaxAmt=0.0825; // this state declares StateTaxAmt as a double and set it equal to the decimal value 0.0825n
double FederalTaxAmt=0.175 ; // this state declares FederalTaxAmt as a double and set it equal to the decimal value 0.175n
double regularpay ; // this state declares regularpay as a double and set it equal to the decimal value
double overtimepay ; // this state declares overtimepay as a double and set it equal to the decimal value if regularpay is greater thaan 40 HoursWorked
double overtimehours ; // this state declares overtimehours as a double and set it equal to the decimal vaule
double regularhours; // this state declares regularhours as a double and set it equal to the decimal vaule
double regularpayrate;
// read the input values
cout << \"Enter the regularpay Rate ? : \";
cin >> regularpayrate ;
cout << \"Enter the overtimehours ? :\" ;
cin >> overtimehours ;
cout << \"Enter the regular hours ? :\" ;
cin >> regularhours ;
// compute the Grosspay, StateTaxAmt, FederalTaxAmt, NetPayAmt, regularpay, overtimepay ,overtimehours
regularpay = regularpayrate * regularhours ;
overtimepay= overtimehours*(regularpayrate/2);
GrossPay = regularpay + overtimepay ;
StateTaxAmt = GrossPay * 0.0825 ; // this state declares StateTaxRate as a double and set it equal to the decimal value 0.0825n
FederalTaxAmt = GrossPay * 0.175 ; // this state declares FederalTaxRate as a double and set it equal to the decimal value 0.175n
NetPayAmt = GrossPay - FederalTaxAmt - StateTaxAmt ;
// display GrossPay , StateTaxAmt , FederalTaxAmt , NetPayAmt, regulatpay, overtimepay, overtimehours
cout.setf(ios::fixed) ; // These lines force currency format in output to 2 decimal pts
cout.setf(ios::showpoint);
cout.precision(2);
cout << \" The regular pay is : $\" << regularpay << endl ;
cout << \" The overtimepay is: $\" << overtimepay << endl ;
cout<<\" The is GrossPay: $\" << GrossPay <<endl;
cout<<\" The is NetPayAmt: $\" << NetPayAmt <<endl;
cout<<\" The is StateTaxAmt: $\" << StateTaxAmt <<endl;
cout<<\" The is FederaltTaxAmt: $\" << FederalTaxAmt <<endl;
}
---------------------------Output-------------------------------------
Enter the regularpay Rate ? : 8.95
Enter the overtimehours ? :2
Enter the regular hours ? :6
The regular pay is : $53.70
The overtimepay is: $8.95
The is GrossPay: $62.65
The is NetPayAmt: $46.52
The is StateTaxAmt: $5.17
The is FederaltTaxAmt: $10.96
------------------------------------------------------------------------------------------------------------------
If you have any query, please feel free to ask
Thanks a lot



