Using parallel arrays and functions to get input

Hi all,

I need to use functions in my main() and three parallel arrays. The first array needs to store the amounts from the file "sales.dat", there are 12 numbers. The second array needs to store the standard sales amounts for each month. The third array should compare the first two arrays and output how many months were above average of the standard sales amount and how many were below. Each row in the "sales.dat" is a separate department, there are 7 departments.

Standard Sales Amounts:

Jan - 23.0
Feb - 33.1
Mar - 21.0
Apr - 23.5
May - 54.0
Jun - 34.3
Jul - 35.0
Aug - 45.0
Sept - 56.3
Oct - 45.6
Nov 34.0
Dec - 55.0

sales.dat
23 33.5 21 23 25 56 54 43 34.2 35.4 34 69.5
24 35.2 24 26 43 56.7 54 32 43 34 34 57.9
24 42 43 35 52 56 67 54 56 45.3 32 32
20 32 45 72 45.4 63.2 45 56 52 65 53 65
34 35 37.5 32 23 45 31 43 52 43 76 65
35 56 63.4 45.2 45.6 56 67.3 45 56.3 67 78 76
34.2 45 62 19 45 39 38 37 82 74 45 58.4

Here is my code if you can run it and let me know what I need to fix, that would be great. Ive been working on this for a few days and cant figure it out. I have errors and cant get it to compile, I have confused myself with my parameter passing.

Once again if you can help me out that would be great!

Thanks,

TECK

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

using namespace std;

void displayHeader();
float readSales(ifstream &fp, float &sales);
float computeAverage(ifstream &fp, float &sales, float avg);
int numberAboveAverage(int &above, int &numbAbove, float &salesAmount[12], float standardSales[12]);
int numbweBelowAverage(int &below, int &numbBelow, float &salesAmount[12], float standardSales[12]);
string performanceOfDept(string &below);

int main()
{
  float salesAmount[12];
  float standardSales[] = {23.0, 33.1, 21.0, 23.5, 54.0, 34.3, 35.0, 45.0, 56.3, 45.6, 34.0, 55.0};
  float compareArrays[12];
  float sales, deptAvg, above, below, performance, avg;
  int numbAbove, numbBelow;

  displayHeader();

  ifstream fp;
  fp.open("sales.dat");
  if(!fp)
    cout<<"Error opening the file!" <<endl;

  while(!fp.eof())
    {
      salesAmount = readSales(&fp, sales);
      deptAvg = computeAverage(&fp, &sales, avg);
      above = numberAboveAverage(&above, &numbAbove);
      below = numbersBelowAverage(&below, &numbBelow)
      performance = performanceOfDept(&below);
    }
  return 0;
}

void displayHeader()
{

  cout<< "Store Statistics"<<endl;
  cout<<"                   "<<endl;
  cout<<"Dept"  <<  "Average"  <<  "Above"  <<  "Below"  <<  "Performance" <<endl;
  cout<<"----------------------------------------------------------------" <<endl;
}

void readSales(ifstream &fp, float &sales)
{
  fp >> sales;
  for(int i = 0; i < sales; i++)
    {
    salesAmount[i] = sales;
    }
}

flaot computeAverage(ifstream &fp, float &sales, float avg)
{
 float total = 0;

  total += sales;
  avg = total/12;
}

int numbersAboveAverage(int &above, int &numbAbove, float &salesAmount[], float &standardSales[])
{
  if(salesAmount[i] > standardSales[i])
    {
      for(above = 0; above <= 7; above++)
        {
          numbAbove += above;
        }
    }
}

int numbersBelowAverage(int &below, int &numbBelow, float &salesAmount[], float &standardSales[])
{
  if(salesAmount[i] < standardSales[i])
    {
      for(int below = 0; below <= 7; below--)
        {
          numbBelow += below;
        }
    }
}

string performanceOfDept(int &below)
{
  if(below > 4)
    cout<<"unsatisfied"<<endl;
  else
    cout<<"Satisfied"<<endl;
}

void displayResults(ifstream &fp, float sales, int above, int below, string performance, float deptAvg, float sale\
sAmount)
{

  cout<<"1"  <<deptAvg <<above <<below <<performance <<endl;
  cout<<"2"  <<deptAvg <<above <<below <<performance <<endl;
  cout<<"3"  <<deptAvg <<above <<below <<performance <<endl;
  cout<<"4"  <<deptAvg <<above <<below <<performance <<endl;
  cout<<"5"  <<deptAvg <<above <<below <<performance <<endl;
  cout<<"6"  <<deptAvg <<above <<below <<performance <<endl;
  cout<<"7"  <<deptAvg <<above <<below <<performance <<endl;
}
Topic archived. No new replies allowed.