Gross pay array

Hi everyone,

I'm in the process of working on a program using void functions to get the gross pay. When I call the functions in main the program isn't running







#include <iostream>
#include <iomanip>
using namespace std;
/* **************************************************
// This program calculates the gross wages *
// for seven employees using their employee *
// ID *
************************************************** */


int employees;
const int num = 7;
void time(long [], int [], int num);
void pay(long [], double [], int []);
void wage(long [], double[], double [], int [], int);


int main()
{
long empID [num]= {5658845, 4520125, 7895122, 8777541, 8451277, 1302850, 7580489};

time(empID[employees],hours[employees], num );
pay(empID[employees], payRate[employees], num);
wage (empID[employees], wages[employees], payRate[employees],hours[employees], num);
return 0;

}

void time(long empID[], int hours[],int num)
{
for (employees = 0; employees < num; employees ++)
{
cout<<"Enter the hours worked for employee ID# "<< empID[employees] << endl;
cin>>hours[employees];
}
}


void pay (long empID[], double payRate[],int num)

{
for (employees = 0; employees < num; employees ++)
{
cout<<"Enter the payrate for employee ID# "<<empID[employees];
cout <<endl;
cin>>payRate[employees];

if (payrate[employees] < 6 )
{

cout<<"Invalid entry. Enter a payrate greater than $6. \n";
cin >> payRate[employees];
}
}
}

void wage (long empID[], double wages[], double payRate[], int hours[], int num )
{


for (employees = 0; employees < num; employees ++)
{
wages[employees] = payRate[employees] * hours[employees];
cout << fixed << showpoint << setprecision(2);
cout << "The gross Pay for employee ID# "<<empID[employees]
<< " is $"<<wages[employees] <<endl;
}

}
Last edited on
Your code doesn't compile. When that happens, the compiler tells you what the problems are. You need to read those error messages and then fix your code.

The first error messages will be something about how the line of code
time(empID[employees],hours[employees], num );
is a problem because hours doesn't exist.

Also, it appears you don't understand how to create arrays or how to use them.

empID[employees] is a single int value, and because employees was never set it's some random value, so this will probably crash even if you did get it running. You need to go back and learn about arrays.
Last edited on
Are you saying that employees need to be set to zero when I declared it as a global variable. In the original message program isn't running = program is not compiling

how is empID[employees] a single int value if it's set up as an element loop calling each element from empID[0] to empID[7]
how is empID[employees] a single int value


In C++, given an array of int, named empID:

empID[0] is the first value in that array. An int.
empID[1] is the second value in that array. An int.
empID[2] is the third value in that array. An int.
...
empID[employees] is a value in that array. An int.

So this function cal:
time(empID[employees],hours[employees], num );
is passing three parameters. The first one is an int (not an array - one int from the array), the second is a value from the non-existent array named hours (this is bad - you can't use arrays that don't exist), and the third is an int.

Are you saying that employees need to be set to zero

I'm saying you need to set it to something. What number should it be? Should it be zero? Should it be seventeen? Should it be minus ten? Work out what value it should be, and set it. It probably is zero by default; it's been so many years since I engaged in the bad practice of global variables that I've no idea anymore what they do.
Last edited on
Hmm. It looks like for me to use void functions with arrays I need to know how to use reference pointers better.

For now I rewrote it without the void functions. Everything is in main with payRate and hours written as nested loops
Last edited on
Topic archived. No new replies allowed.