Need help with my program.

What is wrong with this?

I am getting the wrong output but I am not sure what the problem is. I am putting the outputs just for reference.

Output should look like this:
1
2
3
4
5
6
7
8
Employee Name        Hours Worked          Hourly Pay       Weekly Salary
       abc                5.00                5.00               25.00
       def               20.00               10.00              200.00
       ghi               40.00               15.00              600.00
       jkl               50.00                8.00              440.00

Number of Employees    Total Hrs Worked       Average Hrs Worked           Total Weekly Salary              Average Weekly Salary
         4                   115.00                  28.75                       1265.00                             316.25


Output I am getting:
1
2
3
4
5
6
7
8
Employee Name        Hours Worked          Hourly Pay       Weekly Salary
       def               20.00               10.00              200.00
       ghi               40.00               15.00              600.00
       jkl               50.00                8.00              440.00

Number of Employees    Total Hrs Worked       Average Hrs Worked           Total Weekly Salary              Average Weekly Salary
         3                   110.00                  36.67                       1240.00                             413.33


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

#include <iostream> // library for input/output
#include <conio.h> // console input/output
#include <iomanip> // Controls output formatting
#include <fstream>
#include <string>

using namespace std;

void GetData(ifstream&, string&, double&, double&);
void GetWeeklySalary(double, double, double&);
void GetNumOfEmployee(int&);
void GetAvgHours(int, double, double&);
void GetAvgWeeklySalary(int, double, double&);
void GetTotalHours(double&, double&);
void GetTotalWeeklySalary(double&, double&);

int main()
{
    // declaration section
    ifstream inData;
    ofstream outData;
    string employeeName;
    int numOfEmployees = 0;
    double hoursWorked;
    double hourlyPay;
    double totalHours = 0;
    double avgHours;
    double totalWeeklySalary = 0;
    double avgWeeklySalary;
    double weeklyPay;

    // input section
    inData.open("dataA.txt");
    outData.open("output1256.txt");

    //processing section
    outData << fixed << showpoint << setprecision(2);
    outData << "Employee Name" << setw(20) << "Hours Worked" << setw(20) << "Hourly Pay" << setw(20) << "Weekly Salary" << endl;

    GetData(inData, employeeName, hoursWorked, hourlyPay); // Priming Read

    while( !inData.eof() )
    {
        GetData(inData, employeeName, hoursWorked, hourlyPay);
        GetWeeklySalary(hoursWorked, hourlyPay, weeklyPay);
        GetTotalHours(totalHours, hoursWorked);
        GetTotalWeeklySalary(totalWeeklySalary, weeklyPay);
        GetNumOfEmployee(numOfEmployees);

        outData << setw(10) << employeeName << setw(20) << hoursWorked << setw(20) << hourlyPay << setw(20) << weeklyPay << endl;
    }
    outData << "\nNumber of Employees" << setw(20) << "Total Hrs Worked" << setw(25) << "Average Hrs Worked" << setw(30)
        << "Total Weekly Salary" << setw(35) << "Average Weekly Salary" << endl;

    GetAvgHours(numOfEmployees, totalHours, avgHours);
    GetAvgWeeklySalary(numOfEmployees, totalWeeklySalary, avgWeeklySalary);

    outData << setw(10) << numOfEmployees << setw(25) << totalHours << setw(23) << avgHours << setw(30)
        << totalWeeklySalary << setw(35) << avgWeeklySalary << endl;

    inData.close();
    outData.close();

    _getch();
    return 0;
}
void GetData(ifstream& inData, string& employeeName, double& hoursWorked, double& hourlyPay)
{
    inData >> employeeName >> hoursWorked >> hourlyPay;
}

void GetWeeklySalary(double hoursWorked, double hourlyPay, double &weeklyPay)
{
    double totalOvertimeHours;

    if( hoursWorked > 40 )
    {
        totalOvertimeHours = hoursWorked - 40;
        weeklyPay = ( (hourlyPay * 40) + ((hourlyPay * 1.5) * totalOvertimeHours));
    }
    else
    {
        weeklyPay = hoursWorked * hourlyPay;
    }
}
void GetNumOfEmployee(int& numOfEmployee)
{
    numOfEmployee++;
}
void GetAvgHours(int numOfEmployees, double totalHours, double &avgHours)
{
    avgHours = totalHours / numOfEmployees;
}
void GetAvgWeeklySalary(int numOfEmployees, double totalWeeklySalary, double &avgWeeklySalary)
{
    avgWeeklySalary = totalWeeklySalary / numOfEmployees;
}
void GetTotalHours(double &totalHours, double &hoursWorked)
{
    totalHours += hoursWorked;
}
void GetTotalWeeklySalary(double &totalWeeklySalary, double &weeklyPay)
{
    totalWeeklySalary += weeklyPay;
}
I think you should remove line 41.
I have to have a priming read for this particular assignment.
Well, that is why the first row is missing. You don't do anything with what you read from that first call.
I figured it out.
Topic archived. No new replies allowed.