payroll program problem

Well, I'm working on an assignment for class that will calculate and display the gross wages for a certain amount of employees. Now, what I'm having difficulty with is how to go about displaying the information I have obtained.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <iostream>
#include <iomanip>
using namespace std;

void getWages(long[], int[], float[], float[], int);
void displayWages(long, double, int);

int main()
{
	const int size = 7;
	long empId[size] = {5658845, 4520125, 7895122, 8777541,
        8451277, 1302850, 7580489};
	int hours[size];
	float payRate[size], wages[size];
    
    //get wages for each employee
	getWages(empId, hours, payRate, wages, size);
    

    
	
	return 0;	
}

void getWages(long empId[], int hours[], float payRate[], float wages[], int size)
{
    
    
    for (int index = 0; index <= size; index++)
    {
        
        cout << "Employee number: "<<empId[index] << endl;
        cout << "Number of hours worked: ";
        cin >> hours[index];
        
        //eliminate negative numbers
        while (hours[index] < 0)
        {
            cout << "Please enter a positive number." << endl;
            cout << "Number of hours worked: ";
            cin >> hours[index];
            
        }    
        
        cout << "Employee pay rate: ";
        cin>>payRate[index];
        cout << endl;
        
        wages[index] = hours[index] * payRate[index];
        }
    }


When I run it, so far everything seems gold. It displays each employee number in order, as well as asks the amount of hours worked along with the hourly wage. I've been having a bit of difficulty lately, and I just can't think of how I need to code it to display everything properly. The display would show the employee number, followed by gross wage. What I'm looking for is a general idea of what I need to do, or a shove in the right direction. I understand I need another loop inside of another function, but I can't think of the proper code.
At the end of that for loop you could output their wages, no?

You already have the employee ID but you need user input to calculate their wages right? Just place a cout on line 50 and output their wage after you store it.

EDIT - A better strategy would be to remove the for loop and just output a single employee. Then you could use a loop to output however many employees you need to without having to pass an extra argument.
Last edited on
I can't believe I needed one single line of code to finish the program! While mildly embarrassed, I thank you very much, it now produces exactly what I need.
Topic archived. No new replies allowed.