need help on this program

Read the input file of data ( employees.txt) and store them in arrays. This company can have up to 55 employees

[b]i need to do these following in these program:AND MY CALCULATION IS GOING WRONG

Write a function to read the input file and store the data in arrays.
Write a function to calculate regular pay.
Write a function to calculate overtime pay
Write a function to calculate gross pay.
Write a function to bubble sort the employees into order by last name, first name.
Write any swap functions that are needed.
Write a function to write output to a file called payroll.txt

Format of file is EMPLOYEES.TXT[/b]

1
2
3
4
5
6
7
8
9
10
Hours Pay Rate Employee Number First Name Last 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


HERE IS MY CODE SO FAR:
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
#include <iostream>
#include <cstdio>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
void tellUser();
double regular(int &);
int main()
{
   const int SZ = 55; // size of arrays to hold employees
   string firstname, lastname, fullname, employee; //name of golfer 
  
   float hours, rate, overtime; //scores of four golfer
  // int total; // total of four rounds of golfer
   bool screenonly = false;

   ifstream inputFile; //input filename in program
   ofstream outputFile;

   //read input from file employees.txt
     tellUser(); 
     inputFile.open("employees.txt");
     if (inputFile.fail())
     { 
       cout <<"Error! opening file golfers.txt\n\n";
       cout <<"end of program";
     }
     else
     {
       outputFile.open("payroll.txt");
       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";
     
     outputFile <<" First      Last     Employee      Hours        Rate        Regular      Overtime     Gross\n";
     outputFile <<" Name       Name     Number        Worked       of Pay        Pay          Pay         Pay\n";
     outputFile <<"=========================================================================================\n";
     while (inputFile >> firstname) // there is a line of data to read
     {
        inputFile >> lastname; // read golf score
        inputFile >> employee; // read golf score
        inputFile >> hours; // read golf score
        inputFile >> rate; // read first name of golfer
  //    inputFile >> lastname[i];// read last name of golf
  //
      cout<< setw(7) <<  firstname << setw(13) << lastname;
      cout<< setw(12) << employee << " " << setw(10) << hours << " ";
      cout<< setw(11) << rate << " " << setw(11) << regular <<  " \n";
     // cout<< setw(5) << total << " " << setw(7) << fixed << setprecision(2) << average << " \n";
     // cout<< firstname << " " << lastname << "\n";
    // cout <<"===================================================================================================\n";
    // cout <<"                      Total Gross Pay                                                             \n";

      if (!screenonly)
        {
          fullname = firstname + " " + lastname;      
          outputFile << setw(14) << left << fullname << " ";
          outputFile << setw(4) << fixed << right << employee << " "; 
          outputFile << setw(4) << fixed << right << hours << " ";
          outputFile << setw(4) << fixed << right << rate << " \n";
        }
    }
     inputFile.close(); //close the file after reading it
     cout << "\nInput file closed\n\n";
     if (!screenonly) outputFile.close();
    } 
    return 0;

}
/*
 *function
 *
 */
void tellUser()
{
   cout<<"\nThis program reads a file called golfers.txt,\n";
   cout<<"and it calculates the total and average for each golfer.\n";
   cout<<"output is written to the screen. \n\n";              //tell user what program does
}
/*
 *kkk
 *
 */
double regular(int &)
{
  int empCount;
  double grossPay;
  double hours, rate;
  if(hours <= 40)
      grossPay = hours * rate;
  
}

\AND THIS IS MY OUTPUT:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
This program reads a file called golfers.txt,
and it calculates the total and average for each golfer.
output is written to the screen.

   First        Last     Employee      Hours        Rate        Regular      Ove
   Name         Name      Number       Worked       of Pay       Pay           P
================================================================================
   Jane        Adams       A1234         40          10           1
   Mary      Lincoln       L8765         50          10           1
 Martha   Washington       W7654       25.5       10.85           1
   John        Adams       A9876         52       15.75           1
 George   Washington       W1235         45          25           1
Abraham      Lincoln       L9087      40.25          55           1
William         Tell       T9876         30        9.75           1
  Missy      Muffett       M7654       42.5        12.5           1
  Peter        Piper       P8765         30          10           1

Input file closed
need help
At line 95, you declare two variables, hours and rate, but you don't initialise them. You then immediately try to use their values, despite the fact that you haven't given them any values.

Doesn't your compiler warn you about using uninitialised values?
it does and it has to read data from txt file above
that my my whole to read data from txt and store it in array and how to read data, for example if hours <= 40, so will it know how many hours are there
need help
Try fixing the issue MikeyBoy mentioned and see what happens next.
it does and it has to read data from txt file above
that my my whole to read data from txt and store it in array and how to read data, for example if hours <= 40, so will it know how many hours are there

I don't understand what you're trying to say here.

But your regular function function isn't working, for the reasons I've explained - it's trying to use the values of hours and rate, but you haven't given them any values.

Edit: You should pay attention to the compiler warnings. They usually tell you useful things.
Last edited on
1. Move the file pointer to the next line of your file before starting the loop. One way of doing it can be
char buff[255] = {0}; inputFile.getline(buff, 255);
2. Read the input in a correct sequence as stored in your input file. example:
while (inputFile >> hours) // there is a line of data to read
{
inputFile >> rate;
inputFile >> employee;
inputFile >> firstname;
inputFile >> lastname;
ohh i got it
but give me error it o make one change
Topic archived. No new replies allowed.