Help need with Project

My get payrollTotal and computeHighPay functions are not executing as I intended for them to. Can any one help me with sorting this issue out? Many thanks in advance. :smiley:

Purpose:program that will compute the Healthcare insurance deductions, the total payroll,
and the highest pay in the payroll of all employees in a company using an array of structures.
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

struct incomeInfo {
string emp_name; //employee name
double pay; //employee monthly pay
double  health_Ins_deduction; //employee health insurance deduction

void getData(incomeInfo[], const int);
void compute(incomeInfo* ePtr, const int);
double payrollTotal(const incomeInfo[], const int);
double computeHighPay(const incomeInfo *ePtr, const int);
void displaySummary(const incomeInfo[], const double, const double, const int);

int main() {
const int NUM_EMPS = 2; //size of array
incomeInfo employee[NUM_EMPS]; //array declaration
double total = payrollTotal(employee, NUM_EMPS);
double highPay = computeHighPay(employee, NUM_EMPS);

getData(employee, NUM_EMPS);
compute(employee, NUM_EMPS);
displaySummary(employee, total, highPay, NUM_EMPS);
cout << endl << "Programmer Name: Anthony" << endl;
return 0;
void getData(incomeInfo employee[], const int NUM_EMPS) {
// function to get employee data

for (int i = 0; i < NUM_EMPS; i++) {
//gets employee's names
cout << "Enter employee " << (i + 1) << "'s name: ";
getline(cin, employee[i].emp_name);

//gets employee's monthly pay rates
cout << "Enter employee " << (i + 1) << "'s pay: ";
cin >> employee[i].pay;

void compute(incomeInfo *ePtr, const int NUM_EMPS) {
//function to compute the Healthcare insurance deduction amount of each employee

for (int i = 0; i < NUM_EMPS; i++) {
if ((ePtr + i)->pay >= 5000)
(ePtr + i)->health_Ins_deduction = (.08 * (ePtr + i)->pay);
else if ((ePtr + i)->pay < 3000)
((ePtr + i)->health_Ins_deduction) = (.04 * (ePtr + i)->pay);
((ePtr + i)->health_Ins_deduction) = (.06 * (ePtr + i)->pay);

double payrollTotal(const incomeInfo employee[], const int NUM_EMPS) {
//function to compute the total payroll of the company

double total= 0.0;
for (int i = 0; i < NUM_EMPS; i++) {
total += employee[i].pay;
return total;

double computeHighPay(const incomeInfo *ePtr, const int NUM_EMPS) {
//function to find out the highest employee pay in the payroll

double highpay = (ePtr)[0].pay;
for (int i = 1; i < NUM_EMPS; i++) {
if ((ePtr + i)->pay > highpay)
highpay = (ePtr + i)->pay;
return highpay;

void displaySummary(const incomeInfo employee[], const double total, const double highpay, const int NUM_EMPS) {
//function to display the detail lines of each employee, the total payroll of the company, and the highest pay

system("cls"); //clears the screen for displaying output
cout << setprecision(2) << fixed << showpoint;
cout << "Name                    Pay                    Healthcare deductions"<<endl;
for (int i = 0; i < NUM_EMPS; i++) {
cout << employee[i].emp_name << setw(20) << employee[i].pay << setw(20) <<
employee[i].health_Ins_deduction << endl;

cout << endl << "Total Payroll amount --------> $" << total << endl;
cout << "Highest Total Pay --------> $" << highpay << endl;


Hello, @scrill21, and welcome to the forums.

I edited you post to format your code for the forums. Please review How do I format code in my posts?

Adding indentation would also make your code much easier to read.

As far as what you intended, I ran your code, and see what you likely mean. Consider the order that your code executes. If I wanted to bake a cake, and followed an order like so:

  1. Make a list of ingredients.
  2. Pre-heat Oven
  3. Mix ingredients
  4. Pour batter into pan, and bake.
  5. Buy ingredients from the store.

I would have a problem. Your program has a similar problem.

Good afternoon Midlinder,

Thank you for getting back to me so quickly. Just to clarify, it seems like you are saying the order of my functions are out of order. Another thing I noticed is that my array is being passed by value instead of by reference. Could this be the reason my code is not functioning correctly?

The order the functions appear doesn’t matter. The order they are called in does.

1 Like

Got it! Thank you, I really appreciate your explanation.

1 Like

You’re welcome!