Tyler Brady
Tyler Brady

Reputation: 119

Calculations no processing C++

I'm making a simple payroll calculator and for some reason my "taxes" aren't calculating. When I run the program they just show $0 in the output. Any idea whats causing this? I commented "// Not calculating. Shows $0" on the lines that aren't calculating.

#include <iostream>
using namespace std;

int main()
// Parameters: None
// Returns:    Zero
// Calls:      None
{
int const hourly_wage = 16.78, overtime_rate = 25.17, social_security = 0.06, federal_income = 0.14, state_income = 0.05, union_dues = 10;
int       gross_pay, hours_worked, number_of_dependents, ss_withheld, federal_withheld, state_withheld, net_pay, insurance, overtime_pay, again;

cout << "This program will calculate payroll for an employee." << endl;

    do
    {
        cout << "\n\nEnter the number of hours the employee worked: " << endl;
        cin >> hours_worked;
        if (hours_worked > 40) {
            overtime_pay = (hours_worked - 40) * overtime_rate;
            gross_pay = (40 * hourly_wage) + overtime_pay;
        }
        else {
            gross_pay = hours_worked * hourly_wage;
        }

        cout << "\n\nEnter the number of dependents for employee: " << endl;
        cin >> number_of_dependents;

            if (number_of_dependents >= 3) {
                insurance = 35;
            }
            else {
                insurance = 0;
            }

            // Payroll Calculation
            ss_withheld = gross_pay * social_security;
            federal_withheld = gross_pay * federal_income;
            state_withheld = gross_pay * state_income;
            net_pay = gross_pay - (ss_withheld + federal_withheld + state_withheld + insurance + union_dues);

            cout << "\n\nGross Pay:                 $" << gross_pay << endl;
            cout << "Social Security Withhholding:  $" << ss_withheld << endl; //  Not calculating. Shows $0
            cout << "Federal Withholding:           $" << federal_withheld << endl; //  Not calculating. Shows $0
            cout << "State Withholding:             $" << state_withheld << endl; //  Not calculating. Shows $0
            cout << "Union Dues:                    $" << union_dues << endl;
            cout << "Insurance Deduction:           $" << insurance << endl;
            cout << "Net Pay:                       $" << net_pay << endl;

            cout << "\nDo you want to do another employee(Y/N)? ";
            cin >> again;
    } while (again == 'y' || again == 'Y');

    cout << "\nHope they enjoy the money!" << endl;

    return 0;

}

Upvotes: 1

Views: 47

Answers (1)

ReRoute
ReRoute

Reputation: 317

It looks like you are creating int Const for double values. ie.

    #include "stdafx.h";

#include <iostream>
using namespace std;

int main()
// Parameters: None
// Returns:    Zero
// Calls:      None
{
    int const union_dues = 10;    
    double const hourly_wage = 16.78, overtime_rate = 25.17, social_security = 0.06, federal_income = 0.14, state_income = 0.05;
    double  gross_pay, hours_worked, number_of_dependents, ss_withheld, federal_withheld, state_withheld, net_pay, insurance, overtime_pay, again;


    cout << "This program will calculate payroll for an employee." << endl;

    do {
        cout << "\n\nEnter the number of hours the employee worked: " << endl;
        cin >> hours_worked;
        if (hours_worked > 40) {
            overtime_pay = (hours_worked - 40) * overtime_rate;
            gross_pay = (40 * hourly_wage) + overtime_pay;
        }
        else {
            gross_pay = hours_worked * hourly_wage;
        }

        cout << "\n\nEnter the number of dependents for employee: " << endl;
        cin >> number_of_dependents;

        if (number_of_dependents >= 3) {
            insurance = 35;
        }
        else {
            insurance = 0;
        }

        // Payroll Calculation
        ss_withheld = gross_pay * social_security;
        federal_withheld = gross_pay * federal_income;
        state_withheld = gross_pay * state_income;
        net_pay = gross_pay - (ss_withheld + federal_withheld + state_withheld + insurance + union_dues);

        cout << "\n\nGross Pay:                 $" << gross_pay << endl;
        cout << "Social Security Withhholding:  $" << ss_withheld << endl; //  Not calculating. Shows $0
        cout << "Federal Withholding:           $" << federal_withheld << endl; //  Not calculating. Shows $0
        cout << "State Withholding:             $" << state_withheld << endl; //  Not calculating. Shows $0
        cout << "Union Dues:                    $" << union_dues << endl;
        cout << "Insurance Deduction:           $" << insurance << endl;
        cout << "Net Pay:                       $" << net_pay << endl;

        cout << "\nDo you want to do another employee(Y/N)? ";
        cin >> again;
    } while (again == 'y' || again == 'Y');

    cout << "\nHope they enjoy the money!" << endl;

    return 0;
}

Upvotes: 1

Related Questions