More payroll...

Hey guys,

So I have more payroll to do. This one involves arrays. I'm going to reduce the quantity of variables involved, but I need parallel arrays to display:
Employee name (there will be four entries so I figure this should be the columns since the following variables are a fraction of what I'm working with)
Pay rate
Hours worked
Pay

I need to make my previously-built calculator "feed" info into the appropriate spots on the array... for example, [1][4] should use my hours*rate formula to display the pay. Rows 1 through 3 need to get their info from user input.

Here's what I've got:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <cstdlib>
#include <iostream>

using namespace std;

int main()
{
    int i;
    double displayEmployeeResults[5][4];
    
    for (i=0;i<1;i++)
    {
            cout<<"            "<<"Worker 1"<<"     "<<"Worker 2"<<"     "<<"Worker 3"<<"     "<<"Worker 4"<<endl;
            cout<<"Name       "<<
            cout<<"Hours Worked"<<
            cout<<"Pay Rate    "<<
            cout<<"Pay         "<<

    }
    
    system("PAUSE");
    return EXIT_SUCCESS;
}


Obviously I don't know what I'm doing. I read the tutorial on this site which helped, plus I've been watching videos on YouTube. The prof. wants us to use a function called getInput() but I have no idea what that even means, unfortunately there is no lecture nor decent communication with the professor.

I have two hard parameters for this assignment:
No global variables
Use function prototypes

Thanks in advance for any pointers you guys might have, I always learn more from a handful of posts on here than I do from 50 pages of my textbook. :)
Last edited on
Yep, functions seem something that is needed here.

Do you yet know how to use functions?
Hi Ben,

Not really. I have the math functions all set from previous assignments. Here's my current code:
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include <cstdlib>
#include <iostream>

using namespace std;

int main()
{
    cout<<"Company Payroll Program"<<endl;
    
    void getInput(int empID[],int hoursWorked[],int payRate[],int unionCode[],char payrollType[]);
    {
     int empID[4];
     int hoursWorked[4];
     int payRate[4];
     int unionCode[4];
     char payrollType[4];
     int i;
     
     for(i=0;i<5;i++){
        cout << "Please enter employee ID ";
        cin >> empID[i];
        while( empID[i] >800 || empID[i] <100 )
        {
        cout << "Invalid entry. Please enter employee ID " << endl;//requests user input with error message when invalid # is entered
        cin >> empID[i];//assigns input to a declared variable
        }
        cout<<endl;
        cout << "Please enter payroll type ";
        cin >> payrollType[i];
        while ( payrollType[i] != 'h' && payrollType[i] != 'H')
        {
        cout << "Invalid entry. Please enter payroll type " << endl;//requests user input with error message when input isn't h/H
        cin >> payrollType[i];//assigns input to a declared variable
        }
        cout<<endl;
        cout << "Please enter total hours worked ";
        cin >> hoursWorked[i];
        while( hoursWorked[i] >60 || hoursWorked[i] <0 )
        {
        cout << "Invalid entry. Please enter hours worked " << endl;//requests user input with error message when hours entered aren't between 0 and 60
        cin >> hoursWorked[i];//assigns input to a declared variable
        }
        cout<<endl;
        cout << "Please enter pay rate ";
        cin >> payRate[i];
        while( payRate[i] >45.0 || payRate[i] <8.5 )
        {
        cout << "Invalid entry. Please enter pay rate " << endl;//requests user input with error message when pay rate isn't between 8.50 and 45.0
        cin >> payRate[i];//assigns input to a declared variable
        }
        cout<<endl;
        cout << "Please enter union code ";
        cin >> unionCode[i];
        while( unionCode[i] != 1 && unionCode[i] != 2 && unionCode[i] != 3 )
        {
        cout << "Invalid entry. Please enter union code " << endl;//requests user input with error message when code entered isn't 1,2 or 3
        cin >> unionCode[i];//assigns input to a declared variable
        }
        cout<<endl;
                      }
                      }
  
    

void doCalculations(int hoursWorked[],int payRate[],int unionCode[],double regularPay[],double overtimePay[],double netPay[],double grossPay[],double stateTax[],double federalTax[],double totalTax[],int unionDues[]);
                     {
                     int empID[4];
                     int hoursWorked[4];
                     int payRate[4];
                     int unionCode[4];
                     double regularPay;
                     double overtimePay;
                     double grossPay;
                     double stateTax;
                     double federalTax;
                     double totalTax;
                     double netPay;
                     int unionDues;
                     int i;
                     
                     for(i=0;i<5;i++){    
    
                     if ( hoursWorked[i] > 40 ){
                     regularPay[i] = payRate[i] * hoursWorked[i];//regularPay formula
                     overtimePay[i] = 1.5 * payRate[i] * (hoursWorked[i] - 40);//overtimePay formula
                     grossPay[i] = regularPay[i] + overtimePay[i];//grossPay for employees working more than 40 hours formula
                     }
                     else if ( hoursWorked[i] <= 40 ){
                     grossPay[i] = payRate[i] * hoursWorked[i];//grossPay formula for employees working 40 or fewer hours
                     regularPay[i] = payRate[i] * hoursWorked[i];//regularPay formula
                     overtimePay[i] = 0;//no OT granted
                     }
            
                     if (grossPay[i] < 500)
                     stateTax[i] = 0.0;//if grossPay < 500, stateTax is 0
                     else if (grossPay[i] >= 1000)
                        stateTax[i] = grossPay[i] * 0.05;//if grossPay >=1000, tax at 5%
                        else
                        stateTax[i] = grossPay[i] * 0.03;//otherwise, tax at 3%
                        
                        if (grossPay[i] < 500)
                        federalTax[i] = 0.0;//if grossPay < 500, federalTax is 0
                        else if (grossPay[i] >= 1000)
                        federalTax[i] = grossPay[i] * 0.07;//if grossPay >=1000, tax at 7%
                        else
                        federalTax[i] = grossPay[i] * 0.05;//otherwise, tax at 5%
                            
                            totalTax[i] = stateTax[i] + federalTax[i];//totalTax formula
            
                            switch(unionCode[i]){//based on prior user input of unionCode, a preselected unionDues value is chosen
                            case 1: unionDues[i] = 15;
                            break;
                            case 2: unionDues[i] = 25;
                            break;
                            case 3: unionDues[i] = 35;
                            break;
                            }
            
            netPay[i] = grossPay[i] - (totalTax[i] + unionDues[i]);//netPay formula                                                                                                                                                                                        
}
}

  
    
    system("PAUSE");
    return EXIT_SUCCESS;
}                    



I think it's got the core functionality in place, but I don't know how to make int main call my other functionsvoid getInput, void doCalculations. I shouldn't have to code void input into int main, but get it to run from outside of main, right? It's not a function prototype unless it's declared above the int main, correct?

Any thoughts?
Last edited on
What I'm getting is a conflict between double types being used with subscripts that use i, which is int. Also, I still don't have an array anywhere to be seen.
Bumpity bump...
Topic archived. No new replies allowed.