need help with my source code but it wont complie and giving me errors

i tring to write a emplpoyee payroll code with functions and read data from the txt. file and also need help with bubble sort that sorts and diaplsys starting from emoloyees last name and calculations.

//txt file//
Hours Pay rate emodID first name
40.0 10.00 A1234 Jane Adams
50.0 10.00 L8765 Mary Lincoln
25.5 10.85 W7654 Martha Washington
52.0 15.75 A9876 John Adams
45.0 25.00 W1235 George Washington
40.25 55.00 L9087 Abraham Lincoln
30.0 9.75 T9876 William Tell
42.5 12.50 M7654 Missy Muffett
30.0 10.00 P8765 Peter Piper

and here is my 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include <iostream>
#include <cstdio>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
const int SZ = 55;
void tellUser();
int readData( string [], string [], string [], double [], double []);
int bubbleSort();
int outputScr();
int regular(int);
int overtime(int);
int grossPay(int);
int main()
{
      string firstname[SZ], lastname[SZ];
      string empids[SZ];
      double hours[SZ];
      double rates[SZ];
      ofstream outputFile;
      bool swapmade = false;
      bool screenonly = false;
      char yesno;
      int  i, numemp;   
      
      numemp = readData(firstname, lastname, empids, hours, rates);
      for (i = 0; i < numemp; i++)
      {
          cout << firstname[i] << lastname[i] << empids[i] <<  hours[i]
               << rates[i] << endl; 
      }
      bubbleSort();
      outputScr();
      return 0;
}  //end main
/*
 *
 */
int bubbleSort()
{
       cout << "sorting golfer\n";
       lastpos = numemp;
       do
       {
         lastpos--;
         swapmade = false;
         for ( i = 0; i < lastpos; i++)
         {
            swap(firstn[i], firstn[i+1]);
            swap(lastn[i], lastn[i+1]);
            swap(empID[i], empID[i+1]);
            swap(hrs[i], hrs[i+1]);
            swap(rate[i], rate[i+1]);
            swapmade - true;
         }
       } while(swapmade);
}
/*
 *
 */
int outputScr()
{ 
      cout <<"First   Last   Employee   Hours    Rate   Regular  Overtime   Gross\n";
      cout <<"Name    Name   Number     Worked  of Pay    Pay     Pay        Pay\n";
      cout <<"===================================================================\n";
                
      for ( i=0; i < numemp; i++)
      {
          cout<< setw(7) <<  firstn[i] << setw(13) << lastn[i];
          cout<< setw(12) << empID[i] << " " << setw(10) << hrs[i] << " ";
          cout<< setw(11) << rate[i] << " " << setw(11) << regular <<  " ";
          cout<< setw(11) << overtime << " " << setw(11) << grossPay << " \n";
          if (!screenonly)
          {
              outputFile << setw(7) << left << firstn[i] << " ";
              outputFile << setw(7) << left << lastn[i] << " ";
              outputFile << setw(4) << fixed << right << empID << " "; 
              outputFile << setw(4) << fixed << right << hrs[i] << " ";
              outputFile << setw(4) << fixed << right << rate[i] << " \n";
          }
      }
      if (!screenonly)
      { 
         outputFile.close(); cout << "Output file closed\n\n";}
} // end else
/*
 *function
 *
 */
void tellUser()
{
   cout <<"\nThis program reads a file called employees.txt,\n";
   cout <<"and it calculates the regular pay, overtime pay\n";
   cout <<"and grosspay and total for grosspay for each employee and\n";
   cout <<"sorts the from last name.\n";
   cout<<"output is written to the screen. \n\n"; //tell user what program does
}
/*
 *kkk
 *
 */
int regular(int &)
{
  double grossPay;
  double hours, rate;
  if(hours <= 40)
      grossPay = hours * rate;
}
/*
 *ll
 *
 */
int  overtime(int &)
{
  double hours, rate;
 // const int emp_hrs = 40;
 // const double emp_over = 1.5;
  if (hours >= 40) 
     overtime = (hours - 40) * rate * 1.5;
}
/*
 *dd
 */
int  grossPay(int &)
{
  double hours, rate; 
  if (hours <= 40)
     grossPay = (hours * rate);
  else
     grossPay = ((hours - 40) * rate * 1.5);
}
/*
 *
 *
 */
int readData{string firstn[], string lastn[], string empID[],double hrs[], double rate[]};
{ 
     int numemp;
     ifstream inputFile;
     int i = 0;
     tellUser();  
     // open file and read inputs from employees.txt
     inputFile.open("employees.txt");
     if (inputFile.fail())
     {
        cout << "Error opening file employees.txt \n\n";
        cout << "end of program\n\n";
     }
     else
     {
        while ((inputFile >> hrs[i]) && (i < SZ))
        {
           inputFile >> rate[i];
           inputFile >> empID[i];
           inputFile >> firstn[i];
           inputFile >> lastn[i];
           i++;
        } //end while
        cout << "There were " << i << " employess\n\n";
        numemp = i;
        inputFile.close();
        //************* close input file ****************//
        cout << "input file closed\n\n";
        cout << "Payroll being written to file payroll.txt\n"; //output function
        outputFile.open("payroll.txt"); // output file
        if (outputFile.fail())
        {
           screenonly = true;
           cout <<" output file did not open\n";
           cout <<" output file will only be sent to the screen\n";
        }
}


these are the 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
payroll.cpp: In function ‘int bubbleSort()’:
payroll.cpp:52:8: error: ‘lastpos’ was not declared in this scope
payroll.cpp:52:18: error: ‘numemp’ was not declared in this scope
payroll.cpp:56:10: error: ‘swapmade’ was not declared in this scope
payroll.cpp:57:16: error: ‘i’ was not declared in this scope
payroll.cpp:59:18: error: ‘firstn’ was not declared in this scope
payroll.cpp:60:18: error: ‘lastn’ was not declared in this scope
payroll.cpp:61:18: error: ‘empID’ was not declared in this scope
payroll.cpp:62:18: error: ‘hrs’ was not declared in this scope
payroll.cpp:63:18: error: ‘rate’ was not declared in this scope
payroll.cpp:66:16: error: ‘swapmade’ was not declared in this scope
payroll.cpp: In function ‘int outputScr()’:
payroll.cpp:77:13: error: ‘i’ was not declared in this scope
payroll.cpp:77:22: error: ‘numemp’ was not declared in this scope
payroll.cpp:79:30: error: ‘firstn’ was not declared in this scope
payroll.cpp:79:55: error: ‘lastn’ was not declared in this scope
payroll.cpp:80:30: error: ‘empID’ was not declared in this scope
payroll.cpp:80:61: error: ‘hrs’ was not declared in this scope
payroll.cpp:81:30: error: ‘rate’ was not declared in this scope
payroll.cpp:83:16: error: ‘screenonly’ was not declared in this scope
payroll.cpp:85:15: error: ‘outputFile’ was not declared in this scope
payroll.cpp:92:12: error: ‘screenonly’ was not declared in this scope
payroll.cpp:94:10: error: ‘outputFile’ was not declared in this scope
payroll.cpp: In function ‘int regular()’:
payroll.cpp:114:26: error: assignment of function ‘int grossPay()’
payroll.cpp:114:26: error: cannot convert ‘double’ to ‘int()’ in assignment
payroll.cpp: In function ‘int overtime()’:
payroll.cpp:125:39: error: assignment of function ‘int overtime()’
payroll.cpp:125:39: error: cannot convert ‘double’ to ‘int()’ in assignment
payroll.cpp: In function ‘int grossPay(double&)’:
payroll.cpp:134:30: error: overloaded function with no contextual type information
payroll.cpp:136:43: error: overloaded function with no contextual type information
payroll.cpp: In function ‘int readData(std::string*, std::string*, std::string*, double*, double*)’:
payroll.cpp:171:9: error: ‘outputFile’ was not declared in this scope
payroll.cpp:174:12: error: ‘screenonly’ was not declared in this scope
Last edited on
need help
Your functions cannot "see" the variables declared in main().

So declare all the variables mentioned in the error report as globals (not recommended btw)

or create arguments for your functions and pass some of the variables in main() to them and declare some of the other variables inside the functions.

For example to fix this error...

1
2
payroll.cpp: In function ‘int outputScr()’:
payroll.cpp:77:13: error: ‘i’ was not declared in this scope


declare i as an int in the for loop in outputScr().

Move this code inside outputScr()...

1
2
3
4
5
6
7
8
        cout << "Payroll being written to file payroll.txt\n"; //output function
        outputFile.open("payroll.txt"); // output file
        if (outputFile.fail())
        {
           screenonly = true;
           cout <<" output file did not open\n";
           cout <<" output file will only be sent to the screen\n";
        }


and only declare screenonly and outputFile inside outputScr().



To the OP,

I can see exactly the same problems in your code that I, and others, told you how to fix in one of your previous threads.

If you're not going to pay attention to the answers that people here are giving to your questions, why should we waste our time giving you more answers?
i didnt saw the post until later this morning, i posted my question late night, ill fix it and see it works
here is the code i have corrected and updated:
BUT also need help with bubble sort that sorts and diaplsys starting from emoloyees last name and calculations.

//you can get the text file from above post


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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#include <iostream>
#include <cstdio>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
const int SZ = 55;
void tellUser();
int readData( string [], string [], string [], double [], double []);
int bubbleSort();
int outputScr();
int regular();
int overtime();
int grossPay();
int main()
{
      string firstname[SZ], lastname[SZ];
      string empids[SZ];
      double hours[SZ];
      double rates[SZ];
      ofstream outputFile;
      bool swapmade = false;
      bool screenonly = false;
      char yesno;
      int  i, numemp, lastpos;   
      numemp = readData(firstname, lastname, empids, hours, rates);
      for (i = 0; i < numemp; i++)
      {
          cout << firstname[i] << lastname[i] << empids[i] <<  hours[i]
               << rates[i] << endl; 
      }
      bubbleSort();
      outputScr();
      return 0;
}  //end main
/* bubbleSort()
 * sorts employees with theor last name snd displays in 
 * screen and txt file
 */
int bubbleSort()
{
       string firstn[SZ], lastn[SZ];
       string empID[SZ];
       double hrs[SZ];
       double rate[SZ];
       int  i, numemp, lastpos;
       bool screenonly = false;
       ofstream outputFile;
       bool swapmade = false;
       cout << "sorting golfer\n";
       lastpos = numemp;
       do
       {
         lastpos--;
         swapmade = false;
         for ( i = 0; i < lastpos; i++)
         {
            swap(firstn[i], firstn[i+1]);
            swap(lastn[i], lastn[i+1]);
            swap(empID[i], empID[i+1]);
            swap(hrs[i], hrs[i+1]);
            swap(rate[i], rate[i+1]);
            swapmade - true;
         }
       } while(swapmade);
}
/* outputScr()
 * displays the employee payroll function to the screen and txt file
 */
int outputScr()
{  
      string firstn[SZ], lastn[SZ];
      string empID[SZ];
      double hrs[SZ];
      double rate[SZ];
      int  i, numemp, lastpos;
      bool screenonly = false;
      ofstream outputFile; 
      cout << "Payroll being written to file payroll.txt\n"; //output function
      outputFile.open("payroll.txt"); // output file
      if (outputFile.fail())
      {
           screenonly = true;
           cout <<" output file did not open\n";
           cout <<" output file will only be sent to the screen\n";
      }
      cout <<"First   Last   Employee   Hours    Rate   Regular  Overtime   Gross\n";
      cout <<"Name    Name   Number     Worked  of Pay    Pay     Pay        Pay\n";
      cout <<"===================================================================\n";
                
      for ( i=0; i < numemp; i++)
      {
          cout<< setw(7) <<  firstn[i] << setw(13) << lastn[i];
          cout<< setw(12) << empID[i] << " " << setw(10) << hrs[i] << " ";
          cout<< setw(11) << rate[i] << " " << setw(11) << regular <<  " ";
          cout<< setw(11) << overtime << " " << setw(11) << grossPay << " \n";
          if (!screenonly)
          {
              outputFile << setw(7) << left << firstn[i] << " ";
              outputFile << setw(7) << left << lastn[i] << " ";
              outputFile << setw(4) << fixed << right << empID << " "; 
              outputFile << setw(4) << fixed << right << hrs[i] << " ";
              outputFile << setw(4) << fixed << right << rate[i] << " \n";
          }
      }
      if (!screenonly)
      { 
         outputFile.close(); cout << "Output file closed\n\n";}
} // end else
/* rellUser(0
 * tells about the program to the user
 */
void tellUser()
{
   cout <<"\nThis program reads a file called employees.txt,\n";
   cout <<"and it calculates the regular pay, overtime pay\n";
   cout <<"and grosspay and total for grosspay for each employee and\n";
   cout <<"sorts the from last name.\n";
   cout<<"output is written to the screen. \n\n"; //tell user what program does
}
/* regular()
 * calculates employees regular pay
 */
int regular()
{
  double  hours, rate;
  if(hours <= 40)
      grossPay = hours * rate;
}
/* overtime()
 * calculates employees overtime pay
 */
int  overtime()
{
  double hours, rate;
 // const int emp_hrs = 40;
 // const double emp_over = 1.5;
  if (hours >= 40) 
     overtime = (hours - 40) * rate * 1.5;
}
/* grossPay()
 * calculates employees regular + overtime pay
 */
int  grossPay(double &)
{
  double  hours, rate; 
  if (hours <= 40)
     grossPay = (hours * rate);
  else
     grossPay = ((hours - 40) * rate * 1.5);
}
/**************************************************
 * readData
 * firstname , lastname, empID, hours, rate of pay
 */
int readData(string firstn[], string lastn[], string empID[], double hrs[], double rate[])
{ 
     int numemp;
     ifstream inputFile;
     int i = 0;
     tellUser();  
     // open file and read inputs from employees.txt
     inputFile.open("employees.txt");
     if (inputFile.fail())
     {
        cout << "Error opening file employees.txt \n\n";
        cout << "end of program\n\n";
     }
     else
     {
        while ((inputFile >> hrs[i]) && (i < SZ))
        {
           inputFile >> rate[i];
           inputFile >> empID[i];
           inputFile >> firstn[i];
           inputFile >> lastn[i];
           i++;
        } //end while
        cout << "There were " << i << " employess\n\n";
        numemp = i;
        inputFile.close();
        //************* close input file ****************//
        cout << "input file closed\n\n";
    }
}


NOW THE THE ERROR IS:
1
2
3
4
5
6
7
8
9
payroll.cpp: In function ‘int regular()’:
payroll.cpp:137:26: error: assignment of function ‘int grossPay()’
payroll.cpp:137:26: error: cannot convert ‘double’ to ‘int()’ in assignment
payroll.cpp: In function ‘int overtime()’:
payroll.cpp:148:39: error: assignment of function ‘int overtime()’
payroll.cpp:148:39: error: cannot convert ‘double’ to ‘int()’ in assignment
payroll.cpp: In function ‘int grossPay(double&)’:
payroll.cpp:157:30: error: overloaded function with no contextual type information
payroll.cpp:159:43: error: overloaded function with no contextual type information

need help
Why? So you can ignore it like you usually do?

OK, let's give you one last chance to prove you're not a troll.

You need to read your compiler errors. They are there to help you. They tell you which line of code is causing the error, and what the nature of the error is. They are - sometimes - a bit hard to understand, but it is worth taking the time to try and understand them. You are clearly using Microsoft Visual Studio, which contains detailed help information about all the error and warning messages, so use the help system to get a better understanding.

Let's look at that first error:

payroll.cpp: In function ‘int regular()’:
payroll.cpp:137:26: error: assignment of function ‘int grossPay()’
payroll.cpp:137:26: error: cannot convert ‘double’ to ‘int()’ in assignment


It's telling you that problem is at line 137 of the file payroll.cpp, in the function regular. Let's look at that function:

1
2
3
4
5
6
int regular()
{
  double  hours, rate;
  if(hours <= 40)
      grossPay = hours * rate;
}


What is grossPay? You haven't defined any variable called grossPay in the function, so it must be some global symbol. Looking back through your code, we find:

int grossPay();

So grossPay is the name of a function! It's not a variable, so you can't assign a value to it as if it were a variable. If you want to store the result of hours * rate, you need to declare a variable to store it in.

Now, let's look at the next one:

payroll.cpp: In function ‘int overtime()’:
payroll.cpp:148:39: error: assignment of function ‘int overtime()’
payroll.cpp:148:39: error: cannot convert ‘double’ to ‘int()’ in assignment

It's almost exactly the same error, for exactly the same reason: you're trying to use the name of a function as if it were a variable, assigning a value to it.

Same problem, same solution.

And you're doing exactly the same thing in your grossPay function, too.

In all three of those functions, you also have another major error with your use of uninitialised variables, but you already had that explained to you days ago and you ignored it, so there's no point any of us wasting our time discussing it again.
Last edited on
i got it, so have to declare grossPay as variable in the function, for example double grossPay;
Well, that would make it legal C++, yes.

But why make your variable name the same as the name of a function? Why make things confusing by using the same name for different things? Make it clearer by using a different name altogether.
OP you need to study up on functions, how to pass information to them and how to use return to get a value from them.

Also in your original post you had brackets instead of parentheses for readData() but it didn't show as an error. How did you know to fix that?

int readData{string firstn[], string lastn[], string empID[],double hrs[], double rate[]};
Hi,
@vin
i'm not an expert at such things, but maybe the "overloaded function" error statement at line 31 and 32 of the compiler output are the result of that mistake.
Taking a look at this thing, it really looks simillar to a function that only consists of Var-decl.'s, although ";" seem to be missing.
Maybe the compiler ignores that, because of the error that is seen in the output (?)

Greets,
ok i have correct and update my code and it does work with no errors expect it doesnt do calculations and bubblesort with employees last name
// here is the txt file//
1
2
3
4
5
6
7
8
9
40.0   10.00 A1234 Jane Adams
50.0   10.00 L8765 Mary Lincoln
25.5   10.85 W7654 Martha Washington
52.0   15.75 A9876 John Adams
45.0   25.00 W1235 George Washington
40.25  55.00 L9087 Abraham Lincoln
30.0    9.75 T9876 William Tell
42.5   12.50 M7654 Missy Muffett
30.0   10.00 P8765 Peter Piper

//here is my 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#include <iostream>
#include <cstdio>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
const int SZ = 55;
void tellUser();
int readData( string [], string [], string [], double [], double []);
int bubbleSort();
int outputScr();
void regular();
void overtime();
void grossPay();
int main()
{
      string firstname[SZ], lastname[SZ];
      string empids[SZ];
      double hours[SZ];
      double rates[SZ];
      ofstream outputFile;
      bool swapmade = false;
      bool screenonly = false;
      char yesno;
      int  i, numemp, lastpos;   
      tellUser();    					 // tells the user about the program
      bubbleSort(); 					 // sorts the employees from their last , first name
      outputScr();  					 // display employee payroll information to screen and txt file
      return 0;
}  //end main
/* tellUser()
 * tells about the program to the user
 */
void tellUser()   // tellUser Function
{
   cout <<"\nThis program reads a file called employees.txt,\n";
   cout <<"and it calculates the regular pay, overtime pay\n";
   cout <<"and grosspay and total for grosspay for each employee and\n";
   cout <<"sorts the from last name and output is written to the screen. \n\n"; //tell user what program does
}  //end tellUser Function
/*
 * readData
 * firstname , lastname, empID, hours, rate of pay
 */
int readData(string firstn[], string lastn[], string empID[], double hrs[], double rate[])    //readData Function
{  
     int numemp;
     ifstream inputFile;
     int i = 0;
    // tellUser();  
     // open file and read inputs from employees.txt
     inputFile.open("employees.txt");     //open employees.txt file
     if (inputFile.fail())                // employee.txt fails to open
     { 
        cout << "Error opening file employees.txt \n\n";
        cout << "end of program\n\n";
     }
     else
     {
        while ((inputFile >> hrs[i]) && (i < SZ))
        {
           inputFile >> rate[i];
           inputFile >> empID[i];
           inputFile >> firstn[i];
           inputFile >> lastn[i];
           i++;
        } //end while
       // cout << "There were " << i << " employess\n\n";
       // numemp = i;
        inputFile.close();
        //************* close input file ****************//
     }
}    //en dof readData Function
/* bubbleSort()
 * sorts employees with theor last name snd displays in 
 * screen and txt file
 */
int bubbleSort()       //bubbleSort Function
{
       string firstn[SZ], lastn[SZ];
       string empID[SZ];
       double hrs[SZ];
       double rate[SZ];
       int  i, numemp, lastpos;
       bool screenonly = false;
       ofstream outputFile;
       bool swapmade = false;
    
       lastpos = numemp;
       do
       {
         lastpos--;
         swapmade = false;
         for ( i = 0; i < lastpos; i++)
         {
            swap(firstn[i], firstn[i+1]);
            swap(lastn[i], lastn[i+1]);
           // swap(empID[i], empID[i+1]);
           // swap(hrs[i], hrs[i+1]);
           // swap(rate[i], rate[i+1]);
            swapmade - true;
         }
       } while(swapmade);
}    //end of bubbleSort Function
/* regular()
 * calculates employees regular pay
 */
void regular()
{
   double grossPay;
   double hours, rates;
   if(hours <= 40)
     grossPay = hours * rates;
}
/* overtime()
 * calculates employees overtime pay
 */
void overtime()
{
   double hours, rate, overtime;
   if (hours >= 40) 
       overtime = (hours - 40) * rate * 1.5;
}
/* grossPay()
 * calculates employees regular + overtime pay
 */
void grossPay()
{
   double  hours, rate, grossPay; 
   if (hours <= 40)
       grossPay = (hours * rate);
   else
       grossPay = ((hours - 40) * rate * 1.5);
}
/* outputScr()
 * displays the employee payroll function to the screen and txt file
 */
int outputScr()
{  
      string firstname[SZ], lastname[SZ];
      string empids[SZ];
      double hours[SZ];
      double rates[SZ];
      int  i, numemp, lastpos;
      bool screenonly = false;
      ofstream outputFile; 
      cout << "Payroll being written to file payroll.txt\n\n"; //output function
      outputFile.open("payroll.txt"); // output file
      if (outputFile.fail())
      {
           screenonly = true;
           cout <<" output file did not open\n";
           cout <<" output file will only be sent to the screen\n";
      }
      cout <<"   First       Last     Employee      Hours       Rate      Regular   Overtime     Gross\n";
      cout <<"   Name        Name     Number        Worked      of Pay     Pay       Pay         Pay\n";
      cout <<"============================================================================================\n";
                
      numemp = readData(firstname, lastname, empids, hours, rates);
      for (i = 0; i < numemp; i++)
      {
          cout << setw(7) << firstname[i] << setw(12) << lastname[i];
          cout << setw(11) << empids[i] << " " << setw(12) << fixed << setprecision(2) << hours[i] << " ";
          cout << setw(11) << rates[i] << " " << setw(7) << fixed << setprecision(2) << regular << " ";
          cout << setw(9) << overtime << " " << setw(12) << fixed << setprecision(2) << grossPay << " " << endl; 
      
          if (!screenonly)
          {
                outputFile << setw(7) << left << firstname[i] << " ";
                outputFile << setw(12) << left << lastname[i] << " ";
                outputFile << setw(11) << fixed << right << empids << " "; 
                outputFile << setw(12) << fixed << right << hours[i] << " ";
                outputFile << setw(11) << fixed << right << rates[i] << " \n";
          }
      }

     cout <<"============================================================================================\n";
     cout <<"\t\t\tTotal Gross Pay       \t\t\t\t\t" << fixed << setprecision(2) << grossPay << " \n";
      if (!screenonly)
      { 
         outputFile.close();
         cout << "inpur file closed\n\n";}
} // end main 

and this is the result i get
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
First          Last       Employee     Hours         Rate   Regular    Overtime    Gross
Name           Name        Number      Worked       of Pay    Pay        Pay        Pay
======================================================
Jane           Adams       A1234       40.00        10.00      1           1         1
Mary           Lincoln     L8765       50.00        10.00      1           1         1
Martha         Washington  W7654       25.50        10.85      1           1         1
John           Adams       A9876       52.00        15.75      1           1         1
George         Washington  W1235       45.00        25.00      1           1         1
Abraham        Lincoln     L9087       40.25        55.00      1           1         1
William        Tell        T9876       30.00        9.75       1           1         1
Missy          Muffett     M7654       42.50        12.50      1           1         1
Peter          Piper       P8765       30.00        10.00      1           1         1

===================================================
                        Total Gross Pay                                              1





Topic archived. No new replies allowed.