Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

My program Isn\'t calculating federal or state tax correctly, I tried debugging

ID: 3688843 • Letter: M

Question

My program Isn't calculating federal or state tax correctly, I tried debugging my code but can't figure out what is causing the problem.

My Code:

Payroll.cpp

#include <iostream>

#include "header.h"

#include <iomanip>
#include <stdlib.h>
#include <string>
using namespace std;
double grossPay;
PayRoll::PayRoll()
{
   double federalrateEntered = 0.0;
   cout << "Enter the Federal Tax Rate in % ";
   cin >> federalrateEntered;
{
   if (federalrateEntered = 0.0)
   {
       federalRate;
   }
   else federalrateEntered = federalRate;
}
  
double staterateEntered = 0.0;
   cout << "Enter the State Tax Rate in % ";
   cin >> staterateEntered;
   if (staterateEntered = 0.0)
   {
       stateRate;
   }
   else staterateEntered = stateRate;
}

void PayRoll::choice()
{
   cout << "Press 1 - Calculate payroll for hourly employee" << endl
       << "Press 2 - Calculate payroll for salary employee" << endl
       << "Press 3 - Calculate payroll for contract employee" << endl
       << "Press 4 - Exit" << endl;
   char choice = 0;
   while (choice != '4')
   {
       cout << " Input your choice: " << endl;
       cin >> choice;
       string contractemployeeID;
       switch (choice)
       {
       case '1':
           double hours;
           double payrate;
      
           cout << "Enter hours: " << endl;
           cin >> hours;
           cout << "Enter payrate: " << endl;
           cin >> payrate;
           gross(hours, payrate);

           cout << setprecision(2) << fixed;
           cout << "Gross Pay: " << grossPay << endl
               << "Federal Tax: " << calcFed() << endl
               << "State Tax: " << calcState() << endl
               << "Total Tax: " << calcFed() + calcState() << endl
               << "Net Pay: " << grossPay - (calcFed() + calcState()) << endl;
           break;

       case '2':

           double salary;

           cout << "Enter salary: " << endl;
           cin >> salary;
           salary = (salary);
           gross(salary);

           cout << setprecision(2) << fixed;
           cout << "Gross Pay: " << grossPay << endl
               << "Federal Tax: " << calcFed() << endl
               << "State Tax: " << calcState() << endl
               << "Total Tax: " << calcFed() + calcState() << endl
               << "Net Pay: " << grossPay - (calcFed() + calcState()) << endl;
           break;

       case '3':
           cout << "Enter contract employee ID: " << endl;
           cin >> contractemployeeID;

           if (contractemployeeID.length() <= 1)
           {
               contractemployeeID = true;
           }
           else
           {
               cout << "Enter valid ID" <<endl;
           }
           cout << "Enter hours: " << endl;
           cin >> hours;
           if (hours <= 50)
           {
           cout << "Enter payrate: " << endl;
           cin >> payrate;
           gross(hours, payrate);
           cout << "Employee: " << contractemployeeID << endl;
           cout << setprecision(2) << fixed;
           cout << "Gross Pay: " << grossPay << endl;
           }
           else
           {
               cout << "Contract employees cannot work more than 50 hours per week" << endl;
           }
           break;
          

case '4':
           cout << "Exited" << endl;
           break;
       default:
           cout << "Please try again" << endl;
           break;
       }
   }
}

void PayRoll::gross(double hours, double payrate)
{
   if (hours > 0 && hours <= 40)
       grossPay = hours * payrate;
   if (hours > 40 && hours <= 50)
       grossPay = (40 * payrate) + ((hours - 40) * (payrate * 1.5));
   if (hours > 50)
       grossPay = ((40 * payrate) + ((10) * (payrate * 1.5)) + (hours - 50) * (payrate * 2));
}

void PayRoll::gross(double &salary)
{
   grossPay = salary / 52;
}

double PayRoll::calcFed()
{
   double FedTax = grossPay * (federalRate / 100);
   return FedTax;
}

double PayRoll::calcState()

{
   double StateTax = grossPay * (stateRate / 100);
   return StateTax;
}
double PayRoll::calcNetPay(double &FedTax, double &StateTax)

{
   double NetPay = grossPay - (FedTax + StateTax);
   return NetPay;
}

double PayRoll::fedtaxRate(double r)
{
   return 0.0;
}

double PayRoll::statetaxRate(double r)
{
   return 0.0;
}

main.cpp

#include <iostream>
#include "Header.h"


int main()

{
   PayRoll myPayRoll;
   myPayRoll.choice();
}

header.h

#pragma once
#include <iostream>
#include <iomanip>

class PayRoll
{
public:
   PayRoll();
   void choice();
   void gross(double&);
   void gross(double, double);
   double calcFed();
   double calcState();
   double calcNetPay(double&, double&);


   double fedtaxRate(double federalRate = 10.00);
   double statetaxRate(double stateRate = 5.00);
private:
   double federalRate;
   double stateRate;
};

Project criteria and instructions:

Create a program that calculates and displays (to 2 places of decimal) the weekly
gross pay of hourly employees, contract employees, and salaried employees.
The weekly gross pay of a salaried employee is calculated by dividing the
employee’s annual salary by 52.
The weekly gross pay of an Hourly employee is calculated as follows:
o If the employee works for 40 hours or less, the gross pay is calculated
by multiplying the number of hours worked by the pay rate.
o If the number of hours worked by the employee exceeds 40 hours, but
is not over 50 hours, the employee will receive regular pay for the first
40 hours, and receive time-and-a-half pay for the hours in excess of 40.
o If the number of hours worked by the employee exceeds 50 hours, the
employee will receive regular pay for the first 40 hours, receive timeand-a-half pay for the time between 40 and 50 hours, and receive
double pay for the time over 50 hours.
o An hourly employee must not work more than 60 hours per week.
The weekly gross pay of a contract employee is calculated by multiplying the
number of hours worked by the pay rate, regardless of the number of hours.
A contract employee must not work more than 50 hours per week.
At the start of the program, you should prompt for, and supply the Federal Tax rate
and the State Tax rate to be used for the hourly and salaried employees. No tax is
withheld from the contract employee’s pay check. If 0 is entered for federal tax
rate, use 10% for federal tax rate. If 0 is entered for state tax rate, use 5% for state
tax rate.
The program should also prompt for each employee’s first name, middle name and
last name.


In addition to the Gross Pay, display the following information:
Employee’s name, in the format: First Initial (First character only of first name),
Second Initial (First character only of middle name), and Last Name.
Example: R M Jones

Federal Tax
State Tax
Total Tax
Net Pay

(All amounts should be calculated to 2 places of decimal)
Create separate methods for the calculation of gross pay, and each of the above
amounts.
Create three overloaded functions (one each for the Hourly employees, the
contract employees, and the salaried employees).
The Hourly employee function should receive two values (hours worked and pay
rate), the contract employee should receive three values (hours worked, pay rate,
and the ID of the company the contract employee is from), and the Salaried
employee function should receive one value (yearly salary).
Continue to request, calculate and print employee information until there is no
more employee data to be processed. Your program must be able to process
zero employees, to an infinite number of employees.
Demonstrate the use of the following in your solution:
Function Overloading
Default arguments
Two uses of pass-by-reference using Pointer arguments.
As usual, your solution must be separated into, at least, three source files
(Interface, Implementation, and Test files). There should only be minimal code in
the Test file, just enough to instantiate an object, and invoke the appropriate
function(s).

Explanation / Answer

Note:

Given code modified as requierd without changing variables and method prototype.

Solution

//Header.h
#include <iostream>
#include <iomanip>

class PayRoll
{
   public:
       PayRoll();
       void choice();
       void gross(double&);
       void gross(double, double);
       double calcFed();
       double calcState();
       double calcNetPay(double&, double&);


       double fedtaxRate(double federalRate = 10.00);
       double statetaxRate(double stateRate = 5.00);
   private:
       double federalRate;
       double stateRate;
       double fedTax,stTax,totTax;
};

//PayRoll.cpp

#include <iostream>
#include "header.h"
#include <iomanip>
#include <stdlib.h>
#include <string>
using namespace std;
double grossPay;
PayRoll::PayRoll()
{
    double federalrateEntered = 0.0;
    cout << "Enter the Federal Tax Rate in % ";
    cin >> federalrateEntered;
  
    if (federalrateEntered == 0.0)
    {
        federalRate=10.0;
    }
    else federalRate=federalrateEntered;
  
  
   double staterateEntered = 0.0;
    cout << "Enter the State Tax Rate in % ";
    cin >> staterateEntered;
    if (staterateEntered == 0.0)
    {
        stateRate=5.0;
    }
    else stateRate=staterateEntered;
}

void PayRoll::choice()
{
    cout << "Press 1 - Calculate payroll for hourly employee" << endl
        << "Press 2 - Calculate payroll for salary employee" << endl
        << "Press 3 - Calculate payroll for contract employee" << endl
        << "Press 4 - Exit" << endl;
    char choice = 0;
    while (choice != '4')
    {
        cout << " Input your choice: " << endl;
        cin >> choice;
        string contractemployeeID;
        switch (choice)
        {
        case '1':
            double hours;
            double payrate;
      
            cout << "Enter hours: " << endl;
            cin >> hours;
            cout << "Enter payrate: " << endl;
            cin >> payrate;
            gross(hours, payrate);

            cout << setprecision(2) << fixed;
           fedTax=calcFed();
           stTax=calcState();
           totTax=fedTax+stTax;
            cout << "Gross Pay: " << grossPay << endl
                << "Federal Tax: " << fedTax << endl
                << "State Tax: " << stTax<< endl
                << "Total Tax: " << totTax << endl
                << "Net Pay: " << grossPay - totTax << endl;
            break;

        case '2':

            double salary;

            cout << "Enter salary: " << endl;
            cin >> salary;
            salary = (salary);
            gross(salary);

            cout << setprecision(2) << fixed;
           fedTax=calcFed();
           stTax=calcState();
           totTax=fedTax+stTax;
            cout << "Gross Pay: " << grossPay << endl
                << "Federal Tax: " << fedTax << endl
                << "State Tax: " << stTax<< endl
                << "Total Tax: " << totTax << endl
                << "Net Pay: " << grossPay - totTax << endl;
            break;

        case '3':
            cout << "Enter contract employee ID: " << endl;
            cin >> contractemployeeID;

            if (contractemployeeID.length() <= 1)
            {
                contractemployeeID = true;
            }
            else
            {
                cout << "Enter valid ID" <<endl;
            }
            cout << "Enter hours: " << endl;
            cin >> hours;
            if (hours <= 50)
            {
               cout << "Enter payrate: " << endl;
               cin >> payrate;
               gross(hours, payrate);
               cout << "Employee: " << contractemployeeID << endl;
               cout << setprecision(2) << fixed;
               cout << "Gross Pay: " << grossPay << endl;
            }
            else
            {
                cout << "Contract employees cannot work more than 50 hours per week" << endl;
            }
            break;
          

            case '4':
            cout << "Exited" << endl;
            break;
        default:
            cout << "Please try again" << endl;
            break;
        }
    }
}

void PayRoll::gross(double hours, double payrate)
{
    if (hours > 0 && hours <= 40)
        grossPay = hours * payrate;
    if (hours > 40 && hours <= 50)
        grossPay = (40 * payrate) + ((hours - 40) * (payrate * 1.5));
    if (hours > 50)
        grossPay = ((40 * payrate) + ((10) * (payrate * 1.5)) + (hours - 50) * (payrate * 2));
}

void PayRoll::gross(double &salary)
{
    grossPay = salary / 52;
}

double PayRoll::calcFed()
{
    double FedTax = grossPay * (federalRate / 100);
    return FedTax;
}

double PayRoll::calcState()

{
    double StateTax = grossPay * (stateRate / 100);
    return StateTax;
}
double PayRoll::calcNetPay(double &FedTax, double &StateTax)

{
    double NetPay = grossPay - (FedTax + StateTax);
    return NetPay;
}

double PayRoll::fedtaxRate(double r)
{
    return 0.0;
}

double PayRoll::statetaxRate(double r)
{
    return 0.0;
}

//main.cpp
#include <iostream>
#include "Header.h"
int main()
{
    PayRoll myPayRoll;
    myPayRoll.choice();
}

Result:
Enter the Federal Tax Rate in %
15
Enter the State Tax Rate in %
10
FT15ST10Press 1 - Calculate payroll for hourly employee
Press 2 - Calculate payroll for salary employee
Press 3 - Calculate payroll for contract employee
Press 4 - Exit

Input your choice:
1
Enter hours:
10
Enter payrate:
10
Gross Pay: 100.00
Federal Tax: 15.00
State Tax: 10.00
Total Tax: 25.00
Net Pay: 75.00

Input your choice:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote