Payroll Program Using Functions

I built a payroll program using functions but I'm having some trouble executing it. Can anybody find my errors?

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
#include<fstream.h> //file input output stream

//function prototypes
int readalldata(long int[], float[], const int);
void findovertimehours(int[], int[], int);
void findovertimepay(int[], float[], float[], int);
void findregularhours(int[], int[], int);
void findregularpay(int[], float[], float[], int);
void findgrosspay(float[], float[], float[], int);
void findtaxrate(float[], float[], int);
void findtaxamount(float[], float[], float[], int);
void findnetpay(float[], float[], float[], int);
void printalldata(long int[], int[], float[], float[], float[], float[], float[], int);

void main(){
     const int MAXSIZE=100;   //for maximum of 100 employees
     
     //decleration of variables
     int n;
     long int id[MAXSIZE];
     int hoursworked[MAXSIZE]; overtimehours[MAXSIZE];
     int regularhours[MAXSIZE];
     float hourlyrate[MAXSIZE], regularpay[MAXSIZE],
     float overtimepay[MAXSIZE], float grosspay[MAXSIZE];
     float taxrate[MAXSIZE], float taxamount[MAXSIZE], netpay[MAXSIZE];
     
     //function calls
     n=readalldata(id, hoursworked, hourlyrate, MAXSIZE); //get all data
     findovertimehours(hoursworked, overtimehours, n);
     findovertimepay(overtimehours, hourlyrate, overtimepay, n);
     findregularhours(hoursworked, regularhours, n);
     findregularpay(regularhours, regularpay, hourlyrate, n);
     findgrosspay(regularpay, overtimepay, grosspay, n);
     findtaxrate(grosspay, taxrate, n);
     findtaxamount(grosspay, taxamount, taxrate, n);
     findnetpay(grosspay, netpay, taxamount, n);
     printalldata(id, hoursworked, hourlyrate, overtimepay, 
                      grosspay, taxamount, netpay, n);
}//MAIN
//function definitions
int readalldata(long int id[], int hoursworked[], float hourlyrate[], int n){
    ifstream fin("employee.txt");
    n=0;
    
    while(fin>>id[n]>>hoursworked[n]>>hourlyrate[n]) n++;
    
    fin.close();
    return n;
}//READALLDATA

void findovertimehours(int hoursworked[], int overtimehours[], int n){
     for(int i=0; i<n; i++){
             if(hoursworked[i]<40) overtimehours[i]=hoursworked[i]-40;
             else overtimehours[i]=0;
     }//FOR
}//FINDOVERTIMEHOURS

void findovertimehours(int overtimehours[], float hourlyrate[],
     float overtimepay[], int n){
     for(int i=0; i<n; i++){
             overtimepay[i]=overtimehours[i]*hourlyrate[i]*1.5;
     }//FOR
}//FINDOVERTIMEPAY

void findregularhours(int hoursworked[], int regularhours[], int n){
     for(int i=0; i<n; i++){
             if(hoursworked[i]>40) regularhours[i]=40;
             else regularhours[i]=hoursworked[i];
     }//FOR
}//FINDREGULARHOURS

void findregularpay(int regularhours[], float regularpay[],
                        float hourlyrate[], int n){
      for(int i=0; i<n; i++){
      regularpay[i] = regularhours[i]*hourlyrate[i];
      }//FOR
}//FINDREGULARPAY
void findgrosspay(float regularpay[], float overtimepay[],
                        float grosspay[], int n){
                        for(int i=0; i<n; i++){
                        grosspay[i]=regularpay[i]+overtimepay[i];
        }//FOR
}//FINDGROSSPAY

void findtaxrate(float grosspay[], float taxrate[], int n){
     for(int i=0; i<n; i++){
             if(grosspay[i]>4000.00) taxrate[i]=0.40;
             else if(grosspay[i]>3000.00) taxrate[i]=0.30;
             else if(grosspay[i]>1000.00) taxrate[i]=0.20;
             else taxrate[i]=0.10;
     }//FOR
}//FINDTAXRATE

void findtaxamount(float grosspay[], float taxamount[],
                         float taxrate[], int n){
for(int i=0; i<n; i++){
        taxamount[i]=grosspay[i]*taxrate[i];
        }//FOR
}//FINDTAXAMOUNT

void findnetpay(float grosspay[], float netpay[], float taxamount[], int n){
     for(int i=0; i<n; i++){
          netpay[i]=grosspay[i]-taxamount[i];
     }//FOR
}//FINDNETPAY

void printalldata(long int id[], int hoursworked[], float hourlyrate[],
                       float overtimepay[], float grosspay[], float taxamount[],
                       float netpay[], int n){
cout<<"EMP ID"<<"\t"<<"HOURS"<<"\t"<<"RATE"<<"\t"
           <<"OVERPAY"<<"\t"<<"GROSSPAY"<<"\t"<<"TAX"<<"\t"
           <<"NETPAY"<<endl;
for(int i=0; i<n; i++){
        cout<<""<<id[i]<<"\t"<<hoursworked[i]<<"\t"<<hourlyrate[i]
        <<"\t"<<overtimepay[i]<<"\t\t" <<grosspay[i]<<"\t\t"
        <<taxamount[i]<<"\t"<<netpay[i]<<endl;
        }//FOR
}//PRINTALLDATA
//end source code 


Now I'm suppose to have a different file that inputs the data for the employees which is this and the file is saved as "employee.txt":

8572 40 12.00
6423 40 15.00
7465 40 10.00
2477 40 16.00
5996 40 18.00
If your compiler is giving you errors, what are they? Specifically, what line and what is the description? Also, let's work on the errors before worrying about the file output.
closed account (o3hC5Di1)
As Volatile Pulse said, if you are having errors, please let us know which ones. If they are not compiler errors, let us know what you're expecting the program to do and what it actually does.

On a sidenote, it seems like you are "abusing" comments to make your sourcecode more readable.
A small suggestion that could help you here, as always this is highly personal (but in this case it seems to me like my suggestion could benefit the OP) to format your source code as such:

1
2
3
4
5
6
7
void findnetpay(float grosspay[], float netpay[], float taxamount[], int n)
{
     for(int i=0; i<n; i++)
    {
          netpay[i]=grosspay[i]-taxamount[i];
     }
}


That makes it clear where every curly bracket belongs to, imho, without the need for extra comments.

All the best,
NwN
First off this would cause an error due to your not defining it like are thinking it would. on line 21

 
int hoursworked[MAXSIZE]; overtimehours[MAXSIZE];


should be.
 
int hoursworked[MAXSIZE], overtimehours[MAXSIZE];



line 4 your prototype definition doesn't match the actual function.
 
int readalldata(long int[], float[], const int);


and on line 28
 
n=readalldata(id, hoursworked, hourlyrate, MAXSIZE); //get all data 


hoursworked is of type int. But your function readalldata is expecting it to be a type float.

hourlyrate is of type float.But your function readalldata is expecting it to be a type int.

MAXSIZE doesn't exist acording to your prototype.

then on line 41-49
1
2
3
4
5
6
7
8
9
int readalldata(long int id[], int hoursworked[], float hourlyrate[], int n){
    ifstream fin("employee.txt");
    n=0;
    
    while(fin>>id[n]>>hoursworked[n]>>hourlyrate[n]) n++;
    
    fin.close();
    return n;
}//READALLDATA 
There is no need for your integer n in the function parameters. You just reset it back to 0 on line 43

All together your code is mess from looking over your code a few of your functions will not return how you are expecting them to. But getting rid of those errors will get you back on your way.


I'm gonna go through the necessary steps and try to make changes. Then I'll put my updated info back on this post. I just started programming for the first time 2 months ago and it's been quite overwhelming. Some of the errors the compiler explains I'm trying to understand but I get most of them. With your guys reply's I'm understanding them a little bit more. I'll get back to you guys
Just for starters. Its really easy to mess up when initializing variables.
Like this line here. Although nothing is really wrong and it will work but it is a typo and those could cost you hours trying to fix in some cases.
Notice how you are declaring a TYPE float after regularpay[MAXSIZE] when you are already typing it as a float.

This is wrong:
1
2
float hourlyrate[MAXSIZE], regularpay[MAXSIZE],
     float overtimepay[MAXSIZE], float grosspay[MAXSIZE];


Should be like:
1
2
float hourlyrate[MAXSIZE], regularpay[MAXSIZE]; // Need to add ; here instead of ,
     float overtimepay[MAXSIZE], REMOVER(float) grosspay[MAXSIZE];


Or like:
1
2
float hourlyrate[MAXSIZE], regularpay[MAXSIZE], //Keep this , 
REMOVER(float)overtimepay[MAXSIZE],  REMOVER(float)grosspay[MAXSIZE];


But best to declare them on there own lines even though it is a little more of a pain initially and you do have the ability to declare multiple on a single line. It just makes code easier to read & note and trouble shoot. Optimally should be like especially until you get the hang of it.

This is best for most cases. Declaire them like this.
1
2
3
4
float hourlyrate[MAXSIZE];
float regularpay[MAXSIZE];
float overtimepay[MAXSIZE];
float grosspay[MAXSIZE];




Good luck, Looks like a good project to up your skills on :)


Last edited on
I made a few of the changes. After executing it wouldn't run. My errors are:
Last edited on
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
#include<fstream.h> //file input output stream

//function prototypes
int readalldata(long int[], int[], float[], const int);
void findovertimehours(int[], int[], int);
void findovertimepay(int[], float[], float[], int);
void findregularhours(int[], int[], int);
void findregularpay(int[], float[], float[], int);
void findgrosspay(float[], float[], float[], int);
void findtaxrate(float[], float[], int);
void findtaxamount(float[], float[], float[], int);
void findnetpay(float[], float[], float[], int);
void printalldata(long int[], int[], float[], float[], float[], float[], float[], int);

void main(){
     const int MAXSIZE=100;   //for maximum of 100 employees
     
     //decleration of variables
     int n;
     long int id[MAXSIZE];
     int hoursworked[MAXSIZE], overtimehours[MAXSIZE];
     int regularhours[MAXSIZE];
     float hourlyrate[MAXSIZE], regularpay[MAXSIZE],
     float overtimepay[MAXSIZE], float grosspay[MAXSIZE];
     float taxrate[MAXSIZE], float taxamount[MAXSIZE], netpay[MAXSIZE];
     
     //function calls
     n=readalldata(id, hoursworked, hourlyrate, MAXSIZE); //get all data
     findovertimehours(hoursworked, overtimehours, n);
     findovertimepay(overtimehours, hourlyrate, overtimepay, n);
     findregularhours(hoursworked, regularhours, n);
     findregularpay(regularhours, regularpay, hourlyrate, n);
     findgrosspay(regularpay, overtimepay, grosspay, n);
     findtaxrate(grosspay, taxrate, n);
     findtaxamount(grosspay, taxamount, taxrate, n);
     findnetpay(grosspay, netpay, taxamount, n);
     printalldata(id, hoursworked, hourlyrate, overtimepay, 
                      grosspay, taxamount, netpay, n);
}//MAIN
//function definitions
int readalldata(long int id[], int hoursworked[], float hourlyrate[], int n){
    ifstream fin("employee.txt");
    n=0;
    
    while(fin>>id[n]>>hoursworked[n]>>hourlyrate[n]) n++;
    
    fin.close();
    return n;
}//READALLDATA

void findovertimehours(int hoursworked[], int overtimehours[], int n){
     for(int i=0; i<n; i++){
             if(hoursworked[i]>40) overtimehours[i]=hoursworked[i]-40;
             else overtimehours[i]=0;
     }//FOR
}//FINDOVERTIMEHOURS

void findovertimepay(int overtimehours[], float hourlyrate[],
     float overtimepay[], int n){
     for(int i=0; i<n; i++){
             overtimepay[i]=overtimehours[i]*hourlyrate[i]*1.5;
     }//FOR
}//FINDOVERTIMEPAY

void findregularhours(int hoursworked[], int regularhours[], int n){
     for(int i=0; i<n; i++){
             if(hoursworked[i]>40) regularhours[i]=40;
             else regularhours[i]=hoursworked[i];
     }//FOR
}//FINDREGULARHOURS

void findregularpay(int regularhours[], float regularpay[],
                        float hourlyrate[], int n){
      for(int i=0; i<n; i++){
      regularpay[i] = regularhours[i]*hourlyrate[i];
      }//FOR
}//FINDREGULARPAY
void findgrosspay(float regularpay[], float overtimepay[],
                        float grosspay[], int n){
                        for(int i=0; i<n; i++){
                        grosspay[i]=regularpay[i]+overtimepay[i];
        }//FOR
}//FINDGROSSPAY

void findtaxrate(float grosspay[], float taxrate[], int n){
     for(int i=0; i<n; i++){
             if(grosspay[i]>4000.00) taxrate[i]=0.40;
             else if(grosspay[i]>3000.00) taxrate[i]=0.30;
             else if(grosspay[i]>1000.00) taxrate[i]=0.20;
             else taxrate[i]=0.10;
     }//FOR
}//FINDTAXRATE

void findtaxamount(float grosspay[], float taxamount[],
                         float taxrate[], int n){
for(int i=0; i<n; i++){
        taxamount[i]=grosspay[i]*taxrate[i];
        }//FOR
}//FINDTAXAMOUNT

void findnetpay(float grosspay[], float netpay[], float taxamount[], int n){
     for(int i=0; i<n; i++){
          netpay[i]=grosspay[i]-taxamount[i];
     }//FOR
}//FINDNETPAY

void printalldata(long int id[], int hoursworked[], float hourlyrate[],
                       float overtimepay[], float grosspay[], float taxamount[],
                       float netpay[], int n){
                       cout<<"EMP ID"<<"\t"<<"HOURS"<<"\t"<<"RATE"<<"\t"
           <<"OVERPAY"<<"\t"<<"GROSSPAY"<<"\t"<<"TAX"<<"\t"
           <<"NETPAY"<<endl;
for(int i=0; i<n; i++){
        cout<<""<<id[i]<<"\t"<<hoursworked[i]<<"\t"<<hourlyrate[i]
        <<"\t"<<overtimepay[i]<<"\t\t"<<grosspay[i]<<"\t\t"
        <<taxamount[i]<<"\t"<<netpay[i]<<endl;
        }//FOR
}//PRINTALLDATA
//end source code 


I found a few mistakes and corrected them but still have errors:
1 C:\Users\-6\Desktop\Dev-Cpp\include\c++\3.4.2\backward\fstream.h:31, from C:\Users\-6\Desktop\Dev-Cpp\ESC\Case Study 5 - Functions.cpp In file included from C:/Users/-6/Desktop/Dev-Cpp/include/c++/3.4.2/backward/fstream.h:31, from C:\Users\-6\Desktop\Dev-Cpp\ESC\Case Study 5 - Functions.cpp
1 C:\Users\-6\Desktop\Dev-Cpp\ESC\Case Study 5 - Functions.cpp from C:\Users\-6\Desktop\Dev-Cpp\ESC\Case Study 5 - Functions.cpp
32:2 C:\Users\-6\Desktop\Dev-Cpp\include\c++\3.4.2\backward\backward_warning.h #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
15 C:\Users\-6\Desktop\Dev-Cpp\ESC\Case Study 5 - Functions.cpp `main' must return `int'
24 C:\Users\-6\Desktop\Dev-Cpp\ESC\Case Study 5 - Functions.cpp expected unqualified-id before "float"
24 C:\Users\-6\Desktop\Dev-Cpp\ESC\Case Study 5 - Functions.cpp expected `,' or `;' before "float"
25 C:\Users\-6\Desktop\Dev-Cpp\ESC\Case Study 5 - Functions.cpp expected `,' or `;' before "float"
30 C:\Users\-6\Desktop\Dev-Cpp\ESC\Case Study 5 - Functions.cpp `overtimepay' undeclared (first use this function)
33 C:\Users\-6\Desktop\Dev-Cpp\ESC\Case Study 5 - Functions.cpp `grosspay' undeclared (first use this function)
35 C:\Users\-6\Desktop\Dev-Cpp\ESC\Case Study 5 - Functions.cpp `taxamount' undeclared (first use this function)
36 C:\Users\-6\Desktop\Dev-Cpp\ESC\Case Study 5 - Functions.cpp `netpay' undeclared (first use this function)
110 C:\Users\-6\Desktop\Dev-Cpp\ESC\Case Study 5 - Functions.cpp `cout' undeclared (first use this function)
112 C:\Users\-6\Desktop\Dev-Cpp\ESC\Case Study 5 - Functions.cpp `endl' undeclared (first use this function)
Last edited on
You have it as.
 
#include <fstream.h> 


Should be:
#include <fstream>
Without the .h

That will take care of the first two errors.
Next if you read my last post it would take care of the rest of the errors.
I edited the post and put in Bold the parts that are causing the issues.

if your still confused let me know.
Your errors are on line 23- 25 and explained above
Alright thanks dude let me see what I can come up with
110 C:\Users\-6\Desktop\Dev-Cpp\ESC\Case Study 5 - Functions.cpp `cout' undeclared (first use this function)
112 C:\Users\-6\Desktop\Dev-Cpp\ESC\Case Study 5 - Functions.cpp `endl' undeclared (first use this function)

2 solutions;
using namespace std;
(put it below your includes or something like that)
OR

Before using cout, cin, endl and whatever that belongs to the std:: namespace
std::cout << "hai" << std::endl;

And an example from your code:
1
2
3
4
5
6
for(int i=0; i<n; i++)
       {
        cout<<""<<id[i]<<"\t"<<hoursworked[i]<<"\t"<<hourlyrate[i]
        <<"\t"<<overtimepay[i]<<"\t\t"<<grosspay[i]<<"\t\t"
        <<taxamount[i]<<"\t"<<netpay[i]<<endl;
        }

should be
1
2
3
4
5
6
for(int i=0; i<n; i++)
       {// Only because I don't like to have the brackets on the same line as the for-loop, if-statement and so on
        std::cout<<""<<id[i]<<"\t"<<hoursworked[i]<<"\t"<<hourlyrate[i]
        <<"\t"<<overtimepay[i]<<"\t\t"<<grosspay[i]<<"\t\t"
        <<taxamount[i]<<"\t"<<netpay[i]<< std::endl;// std::cout and std::endl, so the compiler knows that cout and endl exists in std-namespace
        }


What I wrote above is if you don't put using namespace std; somewhere like below your includes or wherever suits you.
Alright I made some changes and here's what I have with errors but many less:

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<fstream> //file input output stream

//function prototypes
int readalldata(long int[], int[], float[], const int);
void findovertimehours(int[], int[], int);
void findovertimepay(int[], float[], float[], int);
void findregularhours(int[], int[], int);
void findregularpay(int[], float[], float[], int);
void findgrosspay(float[], float[], float[], int);
void findtaxrate(float[], float[], int);
void findtaxamount(float[], float[], float[], int);
void findnetpay(float[], float[], float[], int);
void printalldata(long int[], int[], float[], float[], float[], float[], float[], int);

void main(){
     const int MAXSIZE=100;   //for maximum of 100 employees
     
     //decleration of variables
     int n;
     long int id[MAXSIZE];
     int hoursworked[MAXSIZE], overtimehours[MAXSIZE];
     int regularhours[MAXSIZE];
     float hourlyrate[MAXSIZE], regularpay[MAXSIZE],
     overtimepay[MAXSIZE], grosspay[MAXSIZE];
     float taxrate[MAXSIZE], taxamount[MAXSIZE], netpay[MAXSIZE];
     
     //function calls
     n=readalldata(id, hoursworked, hourlyrate, MAXSIZE); //get all data
     findovertimehours(hoursworked, overtimehours, n);
     findovertimepay(overtimehours, hourlyrate, overtimepay, n);
     findregularhours(hoursworked, regularhours, n);
     findregularpay(regularhours, regularpay, hourlyrate, n);
     findgrosspay(regularpay, overtimepay, grosspay, n);
     findtaxrate(grosspay, taxrate, n);
     findtaxamount(grosspay, taxamount, taxrate, n);
     findnetpay(grosspay, netpay, taxamount, n);
     printalldata(id, hoursworked, hourlyrate, overtimepay, 
                      grosspay, taxamount, netpay, n);
}//MAIN
//function definitions
int readalldata(long int id[], int hoursworked[], float hourlyrate[], int n){
    ifstream fin("employee.txt");
    n=0;
    
    while(fin>>id[n]>>hoursworked[n]>>hourlyrate[n]) n++;
    
    fin.close();
    return n;
}//READALLDATA

void findovertimehours(int hoursworked[], int overtimehours[], int n){
     for(int i=0; i<n; i++){
             if(hoursworked[i]>40) overtimehours[i]=hoursworked[i]-40;
             else overtimehours[i]=0;
     }//FOR
}//FINDOVERTIMEHOURS

void findovertimepay(int overtimehours[], float hourlyrate[],
     float overtimepay[], int n){
     for(int i=0; i<n; i++){
             overtimepay[i]=overtimehours[i]*hourlyrate[i]*1.5;
     }//FOR
}//FINDOVERTIMEPAY

void findregularhours(int hoursworked[], int regularhours[], int n){
     for(int i=0; i<n; i++){
             if(hoursworked[i]>40) regularhours[i]=40;
             else regularhours[i]=hoursworked[i];
     }//FOR
}//FINDREGULARHOURS

void findregularpay(int regularhours[], float regularpay[],
                        float hourlyrate[], int n){
      for(int i=0; i<n; i++){
      regularpay[i] = regularhours[i]*hourlyrate[i];
      }//FOR
}//FINDREGULARPAY
void findgrosspay(float regularpay[], float overtimepay[],
                        float grosspay[], int n){
                        for(int i=0; i<n; i++){
                        grosspay[i]=regularpay[i]+overtimepay[i];
        }//FOR
}//FINDGROSSPAY

void findtaxrate(float grosspay[], float taxrate[], int n){
     for(int i=0; i<n; i++){
             if(grosspay[i]>4000.00) taxrate[i]=0.40;
             else if(grosspay[i]>3000.00) taxrate[i]=0.30;
             else if(grosspay[i]>1000.00) taxrate[i]=0.20;
             else taxrate[i]=0.10;
     }//FOR
}//FINDTAXRATE

void findtaxamount(float grosspay[], float taxamount[],
                         float taxrate[], int n){
for(int i=0; i<n; i++){
        taxamount[i]=grosspay[i]*taxrate[i];
        }//FOR
}//FINDTAXAMOUNT

void findnetpay(float grosspay[], float netpay[], float taxamount[], int n){
     for(int i=0; i<n; i++){
          netpay[i]=grosspay[i]-taxamount[i];
     }//FOR
}//FINDNETPAY

void printalldata(long int id[], int hoursworked[], float hourlyrate[],
                       float overtimepay[], float grosspay[], float taxamount[],
                       float netpay[], int n){
                       cout<<"EMP ID"<<"\t"<<"HOURS"<<"\t"<<"RATE"<<"\t"
           <<"OVERPAY"<<"\t"<<"GROSSPAY"<<"\t"<<"TAX"<<"\t"
           <<"NETPAY"<<std::endl;
using namespace std;
for(int i=0; i<n; i++){
        cout<<""<<id[i]<<"\t"<<hoursworked[i]<<"\t"<<hourlyrate[i]
        <<"\t"<<overtimepay[i]<<"\t\t"<<grosspay[i]<<"\t\t"
        <<taxamount[i]<<"\t"<<netpay[i]<<std::endl;
        
        }//FOR
}//PRINTALLDATA
//end source code 


Errors:
15 C:\Users\-6\Desktop\Dev-Cpp\ESC\Case Study 5 - Functions.cpp `main' must return `int'
42 C:\Users\-6\Desktop\Dev-Cpp\ESC\Case Study 5 - Functions.cpp `ifstream' undeclared (first use this function)
42 C:\Users\-6\Desktop\Dev-Cpp\ESC\Case Study 5 - Functions.cpp expected `;' before "fin"
45 C:\Users\-6\Desktop\Dev-Cpp\ESC\Case Study 5 - Functions.cpp `fin' undeclared (first use this function)
110 C:\Users\-6\Desktop\Dev-Cpp\ESC\Case Study 5 - Functions.cpp `cout' undeclared (first use this function)

I'm still confused on where to put using namespace std; by line 10. please explain a little more and anything else ya can. Thanks for the help thus far guys
Last edited on
One thing that all programs with input output streams is #include <iostream> . I believe that will solve all your errors listed above except

[qote]15 C:\Users\-6\Desktop\Dev-Cpp\ESC\Case Study 5 - Functions.cpp `main' must return `int' [/quote]

Change void main() to int int main() and put return 0; at the end of main.

EDIT: Also, as a suggestion for future coding, use double variables rather than float variables. I haven't seen significant differences between the two, but I was told that the computer can more easily use doubles than floats. I also know that the sqrt() function and other functions use doubles for their parameters. This is only an issue if you find typecasting tedious, but not having to typecast will save time.
Last edited on
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
#include <iostream>
#include<fstream>//file input output stream
using namespace std; 

//function prototypes
int readalldata(long int[], int[], float[], const int);
void findovertimehours(int[], int[], int);
void findovertimepay(int[], float[], float[], int);
void findregularhours(int[], int[], int);
void findregularpay(int[], float[], float[], int);
void findgrosspay(float[], float[], float[], int);
void findtaxrate(float[], float[], int);
void findtaxamount(float[], float[], float[], int);
void findnetpay(float[], float[], float[], int);
void printalldata(long int[], int[], float[], float[], float[], float[], float[], int);

int main(){
     const int MAXSIZE=100;   //for maximum of 100 employees
     
     //decleration of variables
     int n;
     long int id[MAXSIZE];
     int hoursworked[MAXSIZE], overtimehours[MAXSIZE];
     int regularhours[MAXSIZE];
     float hourlyrate[MAXSIZE], regularpay[MAXSIZE],
     overtimepay[MAXSIZE], grosspay[MAXSIZE];
     float taxrate[MAXSIZE], taxamount[MAXSIZE], netpay[MAXSIZE];
     
     //function calls
     n=readalldata(id, hoursworked, hourlyrate, MAXSIZE); //get all data
     findovertimehours(hoursworked, overtimehours, n);
     findovertimepay(overtimehours, hourlyrate, overtimepay, n);
     findregularhours(hoursworked, regularhours, n);
     findregularpay(regularhours, regularpay, hourlyrate, n);
     findgrosspay(regularpay, overtimepay, grosspay, n);
     findtaxrate(grosspay, taxrate, n);
     findtaxamount(grosspay, taxamount, taxrate, n);
     findnetpay(grosspay, netpay, taxamount, n);
     printalldata(id, hoursworked, hourlyrate, overtimepay, 
                      grosspay, taxamount, netpay, n);
                      return 0;
}//MAIN
//function definitions
int readalldata(long int id[], int hoursworked[], float hourlyrate[], int n){
    ifstream fin("employee.txt");
    n=0;
    
    while(fin>>id[n]>>hoursworked[n]>>hourlyrate[n]) n++;
    
    fin.close();
    system("PAUSE");
    return n;
}//READALLDATA

void findovertimehours(int hoursworked[], int overtimehours[], int n){
     for(int i=0; i<n; i++){
             if(hoursworked[i]>40) overtimehours[i]=hoursworked[i]-40;
             else overtimehours[i]=0;
     }//FOR
}//FINDOVERTIMEHOURS

void findovertimepay(int overtimehours[], float hourlyrate[],
     float overtimepay[], int n){
     for(int i=0; i<n; i++){
             overtimepay[i]=overtimehours[i]*hourlyrate[i]*1.5;
     }//FOR
}//FINDOVERTIMEPAY

void findregularhours(int hoursworked[], int regularhours[], int n){
     for(int i=0; i<n; i++){
             if(hoursworked[i]>40) regularhours[i]=40;
             else regularhours[i]=hoursworked[i];
     }//FOR
}//FINDREGULARHOURS

void findregularpay(int regularhours[], float regularpay[],
                        float hourlyrate[], int n){
      for(int i=0; i<n; i++){
      regularpay[i] = regularhours[i]*hourlyrate[i];
      }//FOR
}//FINDREGULARPAY
void findgrosspay(float regularpay[], float overtimepay[],
                        float grosspay[], int n){
                        for(int i=0; i<n; i++){
                        grosspay[i]=regularpay[i]+overtimepay[i];
        }//FOR
}//FINDGROSSPAY

void findtaxrate(float grosspay[], float taxrate[], int n){
     for(int i=0; i<n; i++){
             if(grosspay[i]>4000.00) taxrate[i]=0.40;
             else if(grosspay[i]>3000.00) taxrate[i]=0.30;
             else if(grosspay[i]>1000.00) taxrate[i]=0.20;
             else taxrate[i]=0.10;
     }//FOR
}//FINDTAXRATE

void findtaxamount(float grosspay[], float taxamount[],
                         float taxrate[], int n){
for(int i=0; i<n; i++){
        taxamount[i]=grosspay[i]*taxrate[i];
        }//FOR
}//FINDTAXAMOUNT

void findnetpay(float grosspay[], float netpay[], float taxamount[], int n){
     for(int i=0; i<n; i++){
          netpay[i]=grosspay[i]-taxamount[i];
     }//FOR
}//FINDNETPAY

void printalldata(long int id[], int hoursworked[], float hourlyrate[],
                       float overtimepay[], float grosspay[], float taxamount[],
                       float netpay[], int n){
                       cout<<"EMP ID"<<"\t"<<"HOURS"<<"\t"<<"RATE"<<"\t"
           <<"OVERPAY"<<"\t"<<"GROSSPAY"<<"\t"<<"TAX"<<"\t"
           <<"NETPAY"<<endl;

for(int i=0; i<n; i++){
        cout<<""<<id[i]<<"\t"<<hoursworked[i]<<"\t"<<hourlyrate[i]
        <<"\t"<<overtimepay[i]<<"\t\t"<<grosspay[i]<<"\t\t"
        <<taxamount[i]<<"\t"<<netpay[i]<<endl;
        
        }//FOR
}//PRINTALLDATA
//end source code  


Alright I got it to execute. Now I just need to get the "employee.txt" to work so my information on the employees is included:
8572 40 12.00
6423 40 15.00
7465 40 10.00
2477 40 16.00
5996 40 18.00

Any suggestions?
When I hit enter in the executed black box(output) it just says press enter to continue and when I do I can see all of the information but it quickly exits. Do I need a second system("PAUSE") somewhere?
Last edited on
Try cin.get(); right before the return 0;. I don't know the exact problems with system("PAUSE");, but I know there is a user who says that the system function is really bad. I don't really follow their advice when I need a system pause or clear screen, but I try to avoid it. Just personal preference though.
just use a break point at the end of the main function so line 42 when your executing it from the debug.
Depending on your compiler some times you can tell it to not close the window somwhere in the options or you can just execute it from the command line and it will not close.
Personaly system("PAUSE") is a tool that you can use for development but should be taken out for production. Good coding practice to not use it. But just use the break point to stop it from closing. Its there for a reason, To stop the code.
Last edited on
I actually figured it all out and got the program to run with my "employee.txt" as well so thank you guys for all of the help. If anybody has some time can they explain how to add calculations of the the average of all employee net pays (salary). I want to display the computations and average of my employees. Can you show me how? Is it just another function that needs to be added?
Topic archived. No new replies allowed.