Structures adding inFile

I'm having trouble getting the data from the files into the program. when i run it, it gives a value of 0 for everything.
thanks in advance to anyone that can help me with this!

A company has six salespeople. Every month, they go on road trips to sell the
company’s product. At the end of each month, the total sales for each salesperson, together with that salesperson’s ID and the month, is recorded in a file ("sales.txt"). At the end of
each year, the manager of the company wants to see this report in this following
tabular format:

sample input file: the input sales file ("sales.txt) has the following data

12345 1892.00 0.00 494.00 322.00
32214 343.00 892.00 9023.00 0.00
23422 1395.00 1901.00 0.00 0.00
57373 893.00 892.00 8834.00 0.00
35864 2882.00 1221.00 0.00 1223.00
54654 893.00 0.00 392.00 3420.00

Sample input file: The input name file ("empNames.txt") has the following data

12345 John Smith
32214 Gilbert Hope
23422 Mary Arthur
57373 Sam Bedford
35864 Cristal Benard
54654 Jocelyn Tee

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
  #include <iostream>
#include <fstream>
#include <iomanip>
#include <string>

using namespace std;

const int NumberSales = 6;

struct SalesPersonRecord
{
    string ID;
    double saleByQuarter[4];
    double totalSale;
};
void initialize(ifstream& indata, SalesPersonRecord list[], int listSize);
void getData (ifstream& infile, SalesPersonRecord list[], int listSize);
void saleByQuarter (SalesPersonRecord list[], int listSize, double totalByQuarter[]);
void totalSaleByPerson(SalesPersonRecord list[], int listSize);
void printReport(ofstream& outfile, SalesPersonRecord list[], int listSize, double saleByQuarter[]);
void maxSaleByPerson(ofstream& outData, SalesPersonRecord list[], int listSize);
void maxSaleByQuarter(ofstream& outData, double saleByQuarter[]);

int main()
{

    ifstream infile;
    ofstream outfile;
    string inputFile;
    string outputFile;
    double totalSaleByQuarter[4];
    SalesPersonRecord salesPersonList[NumberSales];

    inputFile;
    initialize(infile, salesPersonList, NumberSales);
    infile.close();
    infile.clear();

    outputFile;
    getData(infile, salesPersonList, NumberSales);
    saleByQuarter(salesPersonList, NumberSales, totalSaleByQuarter);
    totalSaleByPerson(salesPersonList, NumberSales);
    printReport(outfile, salesPersonList, NumberSales, totalSaleByQuarter);
    maxSaleByPerson(outfile, salesPersonList, NumberSales);
    maxSaleByQuarter(outfile, totalSaleByQuarter);
    infile.close();
    outfile.close();

    cout<<"\n\n- CFO"<<endl;
    cout<<"November-30-2015"<<endl;

return 0;
}
void initialize(ifstream& indata, SalesPersonRecord list[], int listSize)
{
int index;
int quarter;
for (index = 0; index < listSize; index++)
{
indata >> list[index].ID;
for (quarter = 0; quarter < 4; quarter++)
list[index].saleByQuarter[quarter] = 0.0;
list[index].totalSale = 0.0;
}
}

void getData(ifstream& infile, SalesPersonRecord list[], int listSize)
{
    int index;
    int quarter;
    string ID;
    double amount;

while (!infile.eof()){
	for(int i = 0; i < listSize; i++){
	infile >> list[i].ID;
	infile >> list[i].saleByQuarter[0];
	infile >> list[i].saleByQuarter[1];
	infile >> list[i].saleByQuarter[2];
	infile >> list[i].saleByQuarter[3];
}
}
}
void saleByQuarter(SalesPersonRecord list[], int listSize, double totalByQuarter[])
{
    int quarter;
    int index;

    for (quarter = 0; quarter < 4; quarter++)
    totalByQuarter[quarter] = 0.0;

    for (quarter = 0; quarter < 4; quarter++)
        for (index = 0; index < listSize; index++)
            totalByQuarter[quarter] += list[index].saleByQuarter[quarter];
} //end saleByQuarter

void totalSaleByPerson(SalesPersonRecord list[], int listSize)
{
    int index;
    int quarter;

    for (index = 0; index < listSize; index++)
        for (quarter = 0; quarter < 4; quarter++)
            list[index].totalSale += list[index].saleByQuarter[quarter];
} //end totalSaleByPerson

void printReport(ofstream& outfile, SalesPersonRecord list[], int listSize, double saleByQuarter[])
{
    int index;
    int quarter;

    cout << "            Night Ya Night Prime Coffee             "<<endl;
    cout << "----------- Annual Sales Report - 2013 -----------"<< endl;
    cout << endl;
    cout << " ID       QT1      QT2      QT3       QT4       Total" << endl;
    cout << "___________________________________________________________" << endl;
    for (index = 0; index < listSize; index++)
    {
    cout << list[index].ID << " ";
    for (quarter = 0; quarter < 4; quarter++)
    cout << setw(10)
    << list[index].saleByQuarter[quarter];
    cout << setw(10) << list[index].totalSale << endl;
    }
    cout << "Total ";
    for (quarter = 0; quarter < 4; quarter++)
    cout << setw(10)<< saleByQuarter[quarter];
    cout << endl << endl;
} //end printReport

void maxSaleByPerson(ofstream& outData, SalesPersonRecord list[], int listSize)
{
    int maxIndex=0;
    int index;
    string name;

    for (index = 1; index <listSize; index++)
    if (list[maxIndex].totalSale <list[index].totalSale)
    maxIndex = index;
    cout << "Max Sale by Sales Person:"<<endl;
    cout << "\nSales Person Name: "<<endl;
    cout << "Sales Person ID = "<< list[maxIndex].ID
    << ",\t\tAmount = $" << list[maxIndex].totalSale
    << endl;
} //end maxSaleByPerson

void maxSaleByQuarter(ofstream& outData, double saleByQuarter[])
{
    int quarter;
    int maxIndex = 0;

    for (quarter = 0; quarter < 4; quarter++)
    if (saleByQuarter[maxIndex] < saleByQuarter[quarter])
        maxIndex = quarter;

    cout << "\n\nMax Sale by Quarter:"<<endl;
    cout << "\nQuarter = "<< maxIndex + 1
    << ",\t\tAmount = $" << saleByQuarter[maxIndex]<< endl;
}
SAMPLE RUN
 
–––––––––––– Annual Sales Report ––––––––––––
ID       QT1      QT2       QT3          QT4         Total
12345 1892.00 0.00        494.00    322.00     2708.00
32214 343.00   892.00    9023.00  0.00         10258.00
23422 1395.00 1901.00  0.00        0.00         3296.00
57373 893.00   892.00    8834.00  0.00         10619.00
35864 2882.00 1221.00  0.00        1223.00    5326.00
54654 893.00   0.00       392.00     3420.00    4705.00
Total   XXXXX   XXXXX    XXXXXX   XXXXXXX  XXXXXX

Max Sale by Sales Person:

Sales Person Name:XXXXXX
Sales Person ID =XXXXX ,             Amount = $XXXXX


Max Sale by Quarter:X

Quarter = X,            Amount = $XXXX


Last edited on
closed account (48T7M4Gy)
http://www.cplusplus.com/forum/general/179956/
I'm having trouble getting the data from the files into the program. when i run it, it gives a value of 0 for everything.


Where are you opening any files?
Topic archived. No new replies allowed.