Final Assignment Help

So basically there are 7 functions needed in my assignment. As not to make a huge paragraph at a time I am going to just list the first 2 steps I need help with.

Step 1. A function Called GetData that reads sales data from a file called ("Sales.Txt") and stores the appropriate information in the struct array. I believe I have already completed this step but im just making sure.

Step 2 A function Called TotalQuarter that finds the total sales for each quarter.

I am going to include the sales.Txt File The first column of numbers is the Persons Sales Id Number and is not the sales Data. The other 4 Columns are though. Any Help would be greatly appreciated. Thank you all So much.

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

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

using namespace std;

struct SalesPersonsRecord
{
    int SalesPersonID;      // Sales Person ID
    double saleByQuarter[4]; // Array to store the total sales for each quarter
    double totalSale;        // Calculated salesperson yearly sales amount
};
void Getdata( SalesPersonsRecord);
double TotalQuarter(SalesPersonsRecord);
int main()
{
    SalesPersonsRecord Record;
    Getdata(Record);
    TotalQuarter(Record);


    return 0;
}
void Getdata(SalesPersonsRecord Record)
{
    ifstream fin;
    fin.open("Sales.txt");
    if (!fin)
		cout << "ERROR - File failed to open. make sure that "
		     << "the input file and this file are in the"
		     << "same directory" << endl;
    while(fin >> Record.SalesPersonID)
    {
        fin >>  Record.SalesPersonID;
        for (int i = 0; i < 4; i++)
        {
            fin >>  Record.saleByQuarter[i];
        }
    }
}
double TotalQuarter(SalesPersonsRecord Record)
{
    cout << Record.saleByQuarter[0] << endl;
}
Last edited on
Do the dashes actually appear in your input file?

Do you only have one record in the input file, you only save one record?

Perhaps you should consider a vector of your records?

Also if the file fails to open you probably should skip trying to read the file and notify the calling function of the problem.


The dashes do not appear. They are out there so the numbers don't become all jumbled up. Most of my coding is basic and imcomplete. I'm trying to add up all the sales done by each quarter individually.
Topic archived. No new replies allowed.