Avg Netpays

Can you guys take a look at the below? I am to calculate netpays for 5 employees w/ the class structure. The code will not compile and I believe the problem lies with the while statement in the last block of my code.
I get a "no match for operator>> in std::operator error. Any idea what this means?


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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;

class payroll {
ifstream fin;
public: char ms;
char employeeid [15];
char firstname [15], lastname [15];
int hoursworked [100];
double grosspay[100],  netpay[100], hourlyrate[100], taxrate[100], taxamount[100],overtimepay[100], overtimehours[100],regularpay[100],averageofnetpay[100],sumofnetpay, numberofemployees[100] ;
void findpay();
void findgrosspay();
void findtax();
void findnetpay();
void printheader();
void printdata();
void findavgnetpay();

public: payroll();
~payroll();
void printreport(); };


payroll:: payroll(){
fin.open("5PM.in"); 
}
payroll:: ~payroll(){
fin.close(); }




void payroll:: findpay(){
     int counter = 0;
int i =0;
                  for (i=0; i<counter; i++){
                    if(hoursworked[i] > 40) {
               overtimehours[i] = hoursworked[i] - 40;
               overtimepay[i] = overtimehours[i] * hourlyrate[i]*1.5;
               regularpay[i]= hourlyrate[i] * 40; }
               else{
                    overtimehours[i] = 0;
                    overtimepay[i] = 0;
                    regularpay[i] = hoursworked[i] * hourlyrate[i];}
              }//for
}//payroll


void payroll:: findgrosspay(){   
   int counter = 0;
int i =0;                  
for (i=0; i<counter; i++){
      grosspay[i]=regularpay[i] + overtimepay[i];}
}// end grosspay loop

void payroll:: findtax(){
       int counter = 0;
int i =0;  
        for (i=0; i<counter; i++){
            taxamount[i] = grosspay[i]*.3;}}//end taxamount
            
void payroll:: findnetpay(){  
       int counter = 0;
int i =0;          
     for (i=0; i<counter; i++){
    netpay[i]= grosspay[i]-taxamount[i];}//end netpay
    cout<<endl;}
    
void payroll:: findavgnetpay(){  
       int counter = 0;
int i =0;  
    for (i=0; i<counter; i++){
        sumofnetpay+=netpay[i];} //end of sum of netpay
         for (i=0; i<counter; i++){
             averageofnetpay[i]= sumofnetpay/counter;}}//end of average of netpay
             
       


void payroll:: printheader(){
     cout
     <<setw(8)<<"FName"
     <<setw(8)<<"LName"
     <<setw(4)<<"HW"
     <<setw(5)<<"HR"
     <<setw(5)<<"OTH"
     <<setw(7)<<"OTP"
     <<setw(7)<<"REGP"
     <<setw(7)<<"GROSS"
     <<setw(7)<<"TAX"
     <<setw(9)<<"NET"
     <<setw(9)<<"AVG NET"
     <<endl<<endl;

   cout<<"---------------------------------------------------------------------------"<<endl; }//header
   

void payroll:: printdata(){   
       int counter = 0;
int i =0;  
        for (i=0; i<counter; i++){
     cout
     <<setw(8)<<firstname[i]
     <<setw(8)<<lastname[i]
     <<setw(4)<<hoursworked[i]
     <<setw(5)<<hourlyrate[i]
     <<setw(5)<<overtimehours[i]
     <<setw(7)<<overtimepay[i]
     <<setw(7)<<regularpay[i]
     <<setw(7)<<grosspay[i]
     <<setw(7)<<taxamount[i]
     <<setw(9)<<netpay[i]
     <<setw(9)<<averageofnetpay[i]
     <<endl;}
}



void payroll:: printreport(){
int i;
printheader();
while(fin>>firstname>>lastname>>employeeid>>ms>>hoursworked>>hourlyrate){
findpay();
findgrosspay();
findtax();
findnetpay();
findavgnetpay();
printdata();

i++; }//while
system ("pause");}//printreport;


int main()
{
payroll employee;
employee.printreport(); 
return 0;

}
return 0;

}//end main 
1
2
int hoursworked [100];
fin>>hoursworked;
That is not how you read an array. You need to access per element
2 things, at the end,
1
2
3
4
5
6
7
8
9
10
int main()
{
payroll employee;
employee.printreport(); 
return 0;

}
return 0;

}//end main  


that second return and } are outside of main, they are entirely not needed. They in fact cause an error.

You never included system.

With fin, the while statement doesn't like hoursworked or hourlyrate, if you make them pointers to that location it compiles. Whether it works is another story beyond me.

while(fin>>firstname>>lastname>>employeeid>>ms>>*hoursworked>>*hourlyrate)

Character arrays are treated special, however, your array of an int and double (hoursworked and hourlyrate) need to be told which location in the array they need to go. You can also use
while(fin>>firstname>>lastname>>employeeid>>ms>>hoursworked[0]>>hourlyrate[0])
Last edited on
Topic archived. No new replies allowed.