Employee Payrate Payroll

Ok I redid my code ad it runs but the answer is unreadable any thoughts

I am trying to create a program that calculates a persons hourly wages by the hours worked, also to calculate any overtime by 1.5. and put it in a loop to take multiple employes.

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

#include <iostream>
#include <iomanip>
#include <string.h>
#include <fstream>

using namespace std;

struct data     
{
     //int data; 
     char lastName [25];
     char firstName [25];
     double payRate;
     char shift;
     double monday;
     double tuesday;
     double wednesday;
     double thursday;
     double friday;
     double saturday;
     double sunday;
     double totalHours;
     double overTimePay;
     double income;
     double hoursWorked;
     double regularPay;
     double shift1;
};
//data payrollEmp1[size];

int main ()
{
data payrollEmp1;
    
const int size = 5;
//data payrollEmp1[size];
// const payrollEmp1.lastName << i+1 << payrollEmp1.firstName;

for (int i=0; i<5; i++)
{
     data payrollEmp1;
     payrollEmp1.payRate = 0;
     payrollEmp1.totalHours = 0;
     payrollEmp1.overTimePay = 0;
     payrollEmp1.income = 0;
     payrollEmp1.hoursWorked = 0;
     payrollEmp1.regularPay = 0;
     
     cout << "Enter last name: \n";
     cin >> payrollEmp1.lastName;
     cout << "Enter first name: \n";
     cin >> payrollEmp1.firstName;
     cout << "Enter your hourly payrate: \n";
     cin >> payrollEmp1.payRate;
     cout << "Enter your shift; Days (d) or Nights: (n) \n";
     cin >> payrollEmp1.shift;
     cout << "Enter hours worked Monday: \n";
     cin >> payrollEmp1.monday;
     cout << "Enter hours worked Tuesday: \n";
     cin >> payrollEmp1.tuesday;
     cout << "Enter hours worked Wednesday: \n";
     cin >> payrollEmp1.wednesday;
     cout << "Enter hours worked Thursday: \n";
     cin >> payrollEmp1.thursday;
     cout << "Enter hours worked Friday: \n";
     cin >> payrollEmp1.friday;
     cout << "Enter hours worked Saturday: \n";
     cin >> payrollEmp1.saturday;
     cout << "Enter hours worked Sunday: \n";
     cin >> payrollEmp1.sunday;
}  
   payrollEmp1.hoursWorked = payrollEmp1.monday + payrollEmp1.tuesday + payrollEmp1.wednesday + payrollEmp1.thursday + payrollEmp1.friday + payrollEmp1.saturday + payrollEmp1.sunday;     
  // payrollEmp1.income = (payrollEmp1.hoursWorked * payrollEmp1.payRate) + payrollEmp1.overTimePay;
  // payrollEmp1.overTimePay = 1.5 * payrollEmp1.payRate * payrollEmp1.hoursWorked;
   
 for(int i=0; i<7; i++)
 {
 payrollEmp1.income = payrollEmp1.payRate * payrollEmp1.hoursWorked;
 
if (payrollEmp1.shift == 'N' || payrollEmp1.shift == 'n');
{

 payrollEmp1.shift1 = 1.10 * payrollEmp1.payRate;                    
}
                      
    if (payrollEmp1.hoursWorked > 40) 
    {                            
    payrollEmp1.overTimePay = (payrollEmp1.hoursWorked - 40) * ( payrollEmp1.payRate * 1.5 );
    }
    else if(payrollEmp1.hoursWorked <= 40)
    {
//      payrollEmp1.income = payrollEmp1.hoursWorked * payrollEmp1.payRate);
    }
}
payrollEmp1.income = payrollEmp1.overTimePay + payrollEmp1.regularPay + payrollEmp1.shift1; 
 
// payrollEmp1.wages = 40 * payrollEmp1.rate + 1.5 * payrollEmp1.rate * payrollEmp1.overtime);
// else payrollEmp1.wages = payrollEmp1.hours * payrollEmp1.rate
 
 
     
     
//    cout << "Name: "<< firstName << lastName << endl; 
    //cout << "Payrate: " << payRate << endl;
    //cout << "Hours worked: " << hoursWorked << endl;
    //cout << "Overtime Hours: " << overTimePay << endl;
    //cout << "Total income for the week: " << income << endl;
     
  cout << "              " << endl;
  cout << "Pay To The Order Of             " << payrollEmp1.firstName << endl;
  cout << " " << payrollEmp1.lastName << " $ " << payrollEmp1.income << endl;
  cout << "              " << endl;
//cout << "Pay To The Order Of: " << firstName << lastName << income <<endl;
	
   
system ("pause");
return 0;
}

Last edited on
And what error would be exactly?
Here are my error messages


In function `int main()': 77
request for member `income' in `payrollEmp1', which is of non-class type `data[5]' 77
request for member `payRate' in `payrollEmp1', which is of non-class type `data[5]' 77
request for member `hoursWorked' in `payrollEmp1', which is of non-class type `data[5]' 79
request for member `shift' in `payrollEmp1', which is of non-class type `data[5]' 79
request for member `shift' in `payrollEmp1', which is of non-class type `data[5]' 81
expected primary-expression before "else" 81
expected `;' before "else" 86
request for member `hoursWorked' in `payrollEmp1', which is of non-class type `data[5]' 87
expected `;' before '{' token 106
request for member `firstName' in `payrollEmp1', which is of non-class type `data[5]' 107
request for member `lastName' in `payrollEmp1', which is of non-class type `data[5]' 107
expected `;' before "payrollEmp1" 108
expected primary-expression before '<<' token 108
At global scope: 115
expected declaration before '}' token
I don't know the answer to your question, but I would like to suggest that you use parallel arrays for the for the hours worked on the days of the week, it would make things a lot cleaner.

1
2
3
string days[8] = {" ", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" };

double hoursWorked = {0}; //initialize all values to 0 


1
2
3
4
for(int i = 1; i < 8; ++i) {
     cout << "Enter hours worked " << days[i]: ";
     cin >> payRollEmp1.hoursWorked[i];
} 
Last edited on
I tried that and it still doesn't work.
Is there anyone on here that can help me with this
A couple of the errors...

expected primary-expression before "else" 81
expected `;' before "else" 86

1
2
3
4
if 
//if this is meant to be empty statement, need a semicolon;
else if 
else if 


expected primary-expression before '<<' token 108

cout << " " << payrollEmp1.lastName << " $ " (missing <<) payrollEmp1.income << endl;


There's an extra closing brace at the very end.

-----

Edit: The other errors are in the for(int i=0; i<7; i++) section. It looks like you're trying to create an array of 5 structs. 7 would be outside the bounds. But when you're doing the loops, including for (int i=0; i<5; i++) - I don't see that you're actually accessing the different structs in the array - i.e. there's no [i] subscript being used.
Last edited on
ok I fixed a few things but the out put is unreadable, any thought?
Do you just need to format the output? You can use setw in <iomanip> to format field widths. ( http://www.cplusplus.com/reference/iomanip/setw/ )
that didn't work but good susegestion
Topic archived. No new replies allowed.