Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7816471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:52:58+00:00 2026-06-02T05:52:58+00:00

In my C++ programming class I am tasked to create a payroll recorder for

  • 0

In my C++ programming class I am tasked to create a payroll recorder for 5 employees. One of the requirement is no global variables, therefore I think this requires me to declare variables locally within each individual functions and pass them around.

I know what the errors mean, but I don’t know how to implement the solutions to them. I’m not even sure if the pass by reference/pass by value even make sense with the parameters, I can’t compile because of the 3 errors regarding doCalculations(), displayPayrollSummaryResults() and displayEmployeeResults() having 0 arguments in the main(). Here is the doCalculations() I have.

There is another function before this called getInput, where I take user input of the empID, payrollType…. and put them into payrollArray. The rest of array is used to store calculated data from this function. and a couple more functions afterwards to display the results (see complete code in the end).

void doCalculations(
        double payrollArray[12][5], 
        int &empID, 
        char &payrollType, 
        double &hoursWorked, 
        double &payRate, 
        int &unionCode
        )
    {
        // Defeind Variables - Calculations
        int totalEmployee;
        double totalGrossPay;
        double totalNetPay;
        double highestGrossPay;
        double lowestGrossPay;
        double idHighestGrossPay;
        double idLowestGrossPay;
        double averageGrossPay;
        double averageNetPay;

        // - Pay Calucations
        double regularPay;
        double overtimePay;
        double grossPay;
        // - Tax Calculations
        double stateTax;
        double federalTax;
        double totalTax;
        // - Union Dues
        double unionDues;
        // - Net Pay
        double netPay;

        //Pay Calucations - Work more than 40 hours
        if( hoursWorked > 40 ){
            regularPay = payRate * 40;
            overtimePay = ( 1.5 * payRate ) * ( hoursWorked - 40 );
            grossPay = regularPay + overtimePay;
        }
        //Pay Calucations - Work less than 40 hours
        else{
            regularPay = payRate * hoursWorked;
            overtimePay = 0;
            grossPay = regularPay;
        }
        //Put pay calcuations into array
        payrollArray[4][totalEmployee] = regularPay;
        payrollArray[5][totalEmployee] = overtimePay;
        payrollArray[6][totalEmployee] = grossPay;

        //Taxes Calculations
            // State Tax Calculations
            if( grossPay < 500)
                stateTax = 0;
            else if ( grossPay >= 500 && grossPay <= 1000 )
                stateTax = grossPay * 0.03;
            else if ( grossPay > 1000)
                stateTax = grossPay * 0.05;
            // Federal Tax Calculations
            if( grossPay < 500)
                federalTax = 0;
            else if ( grossPay >= 500 && grossPay <= 1000 )
                federalTax = grossPay * 0.05;
            else if ( grossPay > 1000)
                federalTax = grossPay * 0.07;
            totalTax = stateTax + federalTax;
        // Put Taxes into array
        payrollArray[7][totalEmployee] = stateTax;
        payrollArray[8][totalEmployee] = federalTax;
        payrollArray[9][totalEmployee] = totalTax;

        // Define Variables - Union dues
        if (unionCode = 1)
            unionDues = 15.00;
        else if (unionCode = 2)
            unionDues = 25.00;
        else if (unionCode = 3)
            unionDues = 35.00;

        // Net Pay Calculation
        netPay = grossPay - totalTax - unionDues;

        // Put unionDues & netPay into array
        payrollArray[10][totalEmployee] = unionDues;
        payrollArray[11][totalEmployee] = netPay;

        // Add 1 to totalEmployee per calculation
        totalEmployee += 1;

        // Perpetual Summary Data Calculation

        // Total Gross Pay (Category 6)
        for ( int i = 0; i < totalEmployee; ++i) 
        totalGrossPay += payrollArray[6][i];

        // Total Net Pay (Category 11)
        for ( int i = 0; i < totalEmployee; ++i) 
        totalNetPay += payrollArray[11][i];

        // Find Employee ID number of highest gross pay
            // Compare and Find higest gross pay
            highestGrossPay = 0; // assume highest gross pay is 0 for now
            for (int grossPay = 0; grossPay < totalEmployee; ++grossPay)
            {
                if ( payrollArray[6][grossPay] > highestGrossPay )
                    highestGrossPay = payrollArray[6][grossPay]; // new highestGrossPay, gross pay field is at 6.
            }
            // Using highest gross pay to find corresponding employee ID
            for (int id = 0; id < totalEmployee; ++ id)
            {
                if ( payrollArray[6][id] == highestGrossPay)
                    idHighestGrossPay = payrollArray[0][id]; // the empID field is at 0,
            }

        // Find Employee ID number of lowest gross pay
            // Compare and Find lowest gross pay
            lowestGrossPay = 3150; // assume lowest gross pay is maximum of 3150 for now
            for (int grossPay = 0; grossPay < totalEmployee; ++grossPay)
            {
                if ( payrollArray[6][grossPay] < lowestGrossPay )
                    lowestGrossPay = payrollArray[6][grossPay]; // new lowestGrossPay, gross pay field is at 6.
            }
            // Using highest gross pay to find corresponding employee ID
            for (int id = 0; id < totalEmployee; ++ id)
            {
                if ( payrollArray[6][id] == lowestGrossPay)
                    idLowestGrossPay = payrollArray[0][id]; // the empID field is at 0,
            }

        // Average Gross Pay
        averageGrossPay = totalGrossPay / totalEmployee;
        // Average Net Pay
        averageNetPay = totalNetPay / totalEmployee;
    }

In the main() what to do with newPayroll.doCalculations(“what to put here?”), I just go through trial and error with putting (double payrollArray[12][5], int &empID….), not quite retaining constructor or function prototype of C++ lessons, maybe I am missing some block of codes?

int main()
{
    // Introduction Message
    cout << "WELCOME - EMPLOYEE PAYROLL RECORDER" << endl;
    cout << endl;
    Payroll newPayroll;
    int employeeLimit = 0; // Employee limit counter
    char addEmployee = 'y';// Initial Yes on Add Employee 

    do{
        newPayroll.getInput();
        newPayroll.doCalculations();
        cout << "Would you want to continue adding employees? Enter [Y] or [y] for Yes." << endl;
        cout << "Otherwise Press Any Other Character to Stop adding more Records" << endl;
        cin >> addEmployee;
        ++employeeLimit;
    }while((addEmployee == 'y' || addEmployee == 'Y') && employeeLimit < 5);

    cout << endl; // blank line separator

    newPayroll.displayEmployeeResults();

    cout << endl; // blank line separator

    newPayroll.displayPayrollSummaryResults();

    cout << endl; // blank line separator

    system("PAUSE");
    return 0;
}

Here is the complete code of the program:

#include "stdafx.h"
#include <iostream>
#include <iomanip>

using namespace std;

// Payroll class definition
class Payroll
{

public:
    /* getInput(), Function to accept and validates data, stores valid input data in arrays */
    void getInput()
    {   
        int empID;
        char payrollType;
        double hoursWorked;
        double payRate;
        int unionCode;
        int totalEmployee;

        double payrollArray[12][5]; // Initialize a 12 rows 5 coloums array for storing payroll data.
        char payrollTypeArray[1][5]; // Initialize a separate array for storing payrollType char data.

        cout << "Please Enter Employee ID: " << endl;
        cin >> empID;
        while( empID < 100 || empID > 800 ){
        cout << "The Employee ID Entered is Invalid, Please Enter Employee ID (100 - 800): " << endl;
        cin >> empID;
        }
        //put employee id into array
        payrollArray[0][totalEmployee] = empID;

        cout << "Please Enter payroll type: " << endl;
        cin >> payrollType;
        while( payrollType != 'H' && payrollType != 'h' ){
        cout << "The Payroll Type Entered is Invalid, Please Enter Payroll Type (H or h): " << endl;
        cin >> payrollType; 
        }
        //put payrollType into array
        payrollTypeArray[1][totalEmployee] = payrollType;

        cout << "Please Enter Hours Worked: " << endl;
        cin >> hoursWorked;
        while( hoursWorked < 0 || hoursWorked > 60.0 ){
        cout << "The Hours Worked Entered is Invalid, Please Enter Hours Worked (0 - 60): " << endl;
        cin >> hoursWorked;
        }
        //put hoursWorked into array
        payrollArray[2][totalEmployee] = hoursWorked;

        cout << "Please Enter Pay Rate: " << endl;
        cin >> payRate;
        while( payRate < 8.50 || payRate > 45.00 ){
        cout << "The Hourly Pay Rate Entered is Invalid, Please Enter Pay Rate (8.50 - 45.00): " << endl;
        cin >> payRate;
        }
        //put payRate into array
        payrollArray[3][totalEmployee] = payRate;

        cout << "Please Enter Union Code: " << endl;
        cin >> unionCode;
        while( unionCode !=1 && unionCode !=2 && unionCode !=3 ){
        cout << "The Union Code Entered is Invalid, Please Enter Union Code (1, 2 or 3): " << endl;
        cin >> unionCode;
        }
    }

    /* doCalculations(), performs calculations using data sotred in input arrays, store
       calculation results in arrays, and accumulates totals */
    void doCalculations(
        double payrollArray[12][5], 
        int &empID, 
        char &payrollType, 
        double &hoursWorked, 
        double &payRate, 
        int &unionCode
        )
    {
        // Defeind Variables - Calculations
        int totalEmployee;
        double totalGrossPay;
        double totalNetPay;
        double highestGrossPay;
        double lowestGrossPay;
        double idHighestGrossPay;
        double idLowestGrossPay;
        double averageGrossPay;
        double averageNetPay;

        // - Pay Calucations
        double regularPay;
        double overtimePay;
        double grossPay;
        // - Tax Calculations
        double stateTax;
        double federalTax;
        double totalTax;
        // - Union Dues
        double unionDues;
        // - Net Pay
        double netPay;

        //Pay Calucations - Work more than 40 hours
        if( hoursWorked > 40 ){
            regularPay = payRate * 40;
            overtimePay = ( 1.5 * payRate ) * ( hoursWorked - 40 );
            grossPay = regularPay + overtimePay;
        }
        //Pay Calucations - Work less than 40 hours
        else{
            regularPay = payRate * hoursWorked;
            overtimePay = 0;
            grossPay = regularPay;
        }
        //Put pay calcuations into array
        payrollArray[4][totalEmployee] = regularPay;
        payrollArray[5][totalEmployee] = overtimePay;
        payrollArray[6][totalEmployee] = grossPay;

        //Taxes Calculations
            // State Tax Calculations
            if( grossPay < 500)
                stateTax = 0;
            else if ( grossPay >= 500 && grossPay <= 1000 )
                stateTax = grossPay * 0.03;
            else if ( grossPay > 1000)
                stateTax = grossPay * 0.05;
            // Federal Tax Calculations
            if( grossPay < 500)
                federalTax = 0;
            else if ( grossPay >= 500 && grossPay <= 1000 )
                federalTax = grossPay * 0.05;
            else if ( grossPay > 1000)
                federalTax = grossPay * 0.07;
            totalTax = stateTax + federalTax;
        // Put Taxes into array
        payrollArray[7][totalEmployee] = stateTax;
        payrollArray[8][totalEmployee] = federalTax;
        payrollArray[9][totalEmployee] = totalTax;

        // Define Variables - Union dues
        if (unionCode = 1)
            unionDues = 15.00;
        else if (unionCode = 2)
            unionDues = 25.00;
        else if (unionCode = 3)
            unionDues = 35.00;

        // Net Pay Calculation
        netPay = grossPay - totalTax - unionDues;

        // Put unionDues & netPay into array
        payrollArray[10][totalEmployee] = unionDues;
        payrollArray[11][totalEmployee] = netPay;

        // Add 1 to totalEmployee per calculation
        totalEmployee += 1;

        // Perpetual Summary Data Calculation

        // Total Gross Pay (Category 6)
        for ( int i = 0; i < totalEmployee; ++i) 
        totalGrossPay += payrollArray[6][i];

        // Total Net Pay (Category 11)
        for ( int i = 0; i < totalEmployee; ++i) 
        totalNetPay += payrollArray[11][i];

        // Find Employee ID number of highest gross pay
            // Compare and Find higest gross pay
            highestGrossPay = 0; // assume highest gross pay is 0 for now
            for (int grossPay = 0; grossPay < totalEmployee; ++grossPay)
            {
                if ( payrollArray[6][grossPay] > highestGrossPay )
                    highestGrossPay = payrollArray[6][grossPay]; // new highestGrossPay, gross pay field is at 6.
            }
            // Using highest gross pay to find corresponding employee ID
            for (int id = 0; id < totalEmployee; ++ id)
            {
                if ( payrollArray[6][id] == highestGrossPay)
                    idHighestGrossPay = payrollArray[0][id]; // the empID field is at 0,
            }

        // Find Employee ID number of lowest gross pay
            // Compare and Find lowest gross pay
            lowestGrossPay = 3150; // assume lowest gross pay is maximum of 3150 for now
            for (int grossPay = 0; grossPay < totalEmployee; ++grossPay)
            {
                if ( payrollArray[6][grossPay] < lowestGrossPay )
                    lowestGrossPay = payrollArray[6][grossPay]; // new lowestGrossPay, gross pay field is at 6.
            }
            // Using highest gross pay to find corresponding employee ID
            for (int id = 0; id < totalEmployee; ++ id)
            {
                if ( payrollArray[6][id] == lowestGrossPay)
                    idLowestGrossPay = payrollArray[0][id]; // the empID field is at 0,
            }

        // Average Gross Pay
        averageGrossPay = totalGrossPay / totalEmployee;
        // Average Net Pay
        averageNetPay = totalNetPay / totalEmployee;
    }




    /* displayEmployeeResults(), displays employee IDs and calculations results that are stored in arrays.*/
    void displayEmployeeResults(
        double payrollArray[12][5], 
        char payrollTypeArray[1][5], 
        int &totalEmployee
        ) 
    {
        int employeeCount;
        int arrayDataSetw = 5;
        int arrayTitleSetw = 12;

        //Display Data Array
            cout << setw(50) <<"Individual Employee Payroll Record" << endl;
            cout << endl;
            // Employee ID title
            cout << setw(arrayTitleSetw) << "Employee ID";
                for (employeeCount = 0; employeeCount < totalEmployee; ++employeeCount)
                cout << setw(arrayDataSetw) << payrollArray[0][employeeCount] << setw(arrayDataSetw);
                cout << endl;
            // Payroll Type title
            cout << setw(arrayTitleSetw) << "Payroll Type";
                for (employeeCount = 0; employeeCount < totalEmployee; ++employeeCount)
                cout << setw(arrayDataSetw) << payrollTypeArray[1][employeeCount] << setw(arrayDataSetw);
                cout << endl;
            // Hours Worked title
            cout << setw(arrayTitleSetw) << "Hours Worked";
                for (employeeCount = 0; employeeCount < totalEmployee; ++employeeCount)
                cout << setw(arrayDataSetw) << payrollArray[2][employeeCount] << setw(arrayDataSetw);
                cout << endl;
            // Pay Rate title
            cout << setw(arrayTitleSetw) << "Pay Rate";
                for (employeeCount = 0; employeeCount < totalEmployee; ++employeeCount)
                cout << setw(arrayDataSetw) << "$" << payrollArray[3][employeeCount] << setw(arrayDataSetw);
                cout << endl;
            // Regular Pay title
            cout << setw(arrayTitleSetw) << "Regular Pay";
                for (employeeCount = 0; employeeCount < totalEmployee; ++employeeCount)
                cout << setw(arrayDataSetw) << "$" << payrollArray[4][employeeCount] << setw(arrayDataSetw);
                cout << endl;
            // Overtime Pay title
            cout << setw(arrayTitleSetw) << "Overtime Pay";
                for (employeeCount = 0; employeeCount < totalEmployee; ++employeeCount)
                cout << setw(arrayDataSetw) << "$" << payrollArray[5][employeeCount] << setw(arrayDataSetw);
                cout << endl;
            // Gross Pay title
            cout << setw(arrayTitleSetw) << "Gross Pay";
                for (employeeCount = 0; employeeCount < totalEmployee; ++employeeCount)
                cout << setw(arrayDataSetw) << "$" << payrollArray[6][employeeCount] << setw(arrayDataSetw);
                cout << endl;
            // State Tax title
            cout << setw(arrayTitleSetw) << "State Tax";
                for (employeeCount = 0; employeeCount < totalEmployee; ++employeeCount)
                cout << setw(arrayDataSetw) << "$" << payrollArray[7][employeeCount] << setw(arrayDataSetw);
                cout << endl;
            // Federal Tax title
            cout << setw(arrayTitleSetw) << "Federal Tax";
                for (employeeCount = 0; employeeCount < totalEmployee; ++employeeCount)
                cout << setw(arrayDataSetw) << "$" << payrollArray[8][employeeCount] << setw(arrayDataSetw);
                cout << endl;
            // Total Tax title
            cout << setw(arrayTitleSetw) << "Total Tax";
                for (employeeCount = 0; employeeCount < totalEmployee; ++employeeCount)
                cout << setw(arrayDataSetw) << "$" << payrollArray[9][employeeCount] << setw(arrayDataSetw);
                cout << endl;
            // Union Dues title
            cout << setw(arrayTitleSetw) << "Union Dues";
                for (employeeCount = 0; employeeCount < totalEmployee; ++employeeCount)
                cout << setw(arrayDataSetw) << "$" << payrollArray[10][employeeCount] << setw(arrayDataSetw);
                cout << endl;
            // Net Pay title
            cout << setw(arrayTitleSetw) << "Net Pay";
                for (employeeCount = 0; employeeCount < totalEmployee; ++employeeCount)
                cout << setw(arrayDataSetw) << "$" << payrollArray[11][employeeCount] << setw(arrayDataSetw);
                cout << endl;
    }

    /* displayPayrollSummaryResults(), displays summary totals and averages */
    void displayPayrollSummaryResults(
        int &totalEmployee, 
        double &totalGrossPay, 
        double &totalNetPay, 
        double &idHighestGrossPay, 
        double &highestGrossPay, 
        double &idLowestGrossPay, 
        double &lowestGrossPay, 
        double &averageGrossPay, 
        double &averageNetPay
        ) 
    {
        int summaryDataSetw = 47;
        // Display Summary Data
        cout << setw(50) <<"Employee Payroll Summary" << endl;
        cout << endl;
        cout << setw(summaryDataSetw) << "Total Number of Employees on record is: " << totalEmployee << endl;
        cout << setw(summaryDataSetw) << "Total Gross Pay is: $"  << totalGrossPay << endl;
        cout << setw(summaryDataSetw) << "Total Net Pay is: $"  << totalNetPay << endl;
        cout << setw(summaryDataSetw) << "Employee with the highest gross pay: Employee #" << idHighestGrossPay << " earned $" << highestGrossPay << endl;
        cout << setw(summaryDataSetw) << "Employee with the lowest gross pay: Employee #" << idLowestGrossPay << " earned $" << lowestGrossPay << endl;
        cout << setw(summaryDataSetw) << "Average gross pay is: $"  << averageGrossPay << endl;
        cout << setw(summaryDataSetw) << "Average net pay is: $"  << averageNetPay << endl;

    }
};

int main()
{
    // Introduction Message
    cout << "WELCOME - EMPLOYEE PAYROLL RECORDER" << endl;
    cout << endl;
    Payroll newPayroll;
    int employeeLimit = 0; // Employee limit counter
    char addEmployee = 'y';// Initial Yes on Add Employee 

    do{
        newPayroll.getInput();
        newPayroll.doCalculations();
        cout << "Would you want to continue adding employees? Enter [Y] or [y] for Yes." << endl;
        cout << "Otherwise Press Any Other Character to Stop adding more Records" << endl;
        cin >> addEmployee;
        ++employeeLimit;
    }while((addEmployee == 'y' || addEmployee == 'Y') && employeeLimit < 5);

    cout << endl; // blank line separator

    newPayroll.displayEmployeeResults();

    cout << endl; // blank line separator

    newPayroll.displayPayrollSummaryResults();

    cout << endl; // blank line separator

    system("PAUSE");
    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T05:52:59+00:00Added an answer on June 2, 2026 at 5:52 am

    This is because You function call arguments mis matches your function definition.
    Eg:

    void doCalculations(
            double payrollArray[12][5], 
            int &empID, 
            char &payrollType, 
            double &hoursWorked, 
            double &payRate, 
            int &unionCode
            )
    

    Is your definition and has 6 parameters. You need arguments to Invoke this function.
    But instead you call it with 0 arguments

    newPayroll.doCalculations();
    

    and your displayEmployeeResults also need 3 parameters:

    void displayEmployeeResults(
            double payrollArray[12][5], 
            char payrollTypeArray[1][5], 
            int &totalEmployee
            ) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This was a question in one my friend's programming class. Q. How do you
So for my programming class we have had a project to create a virtual
Disclaimer: This is for a programming class, but it is not the answer or
In my programming class we currently have a project that requires us to take
For my programming class I have to write a linked list class. One of
I've been teaching a C++ programming class for many years now and one of
I am a TA for a programming class. There is one assignment in which
I am taking a programming class (for noobs) and I need to create the
In my MIPs Assembly Programming class I've been tasked with writing a program that
I am taking a C programming class this semester, and was somehow allowed to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.