Need Help!!

Pages: 12
the compiler is giving me a fatal error because of the bool meet[] array but i dont know how to fix the error, unless im missing something obvious
What error and on what line? Why do you try to store characters 't' and 'f' into a bool variable, even when agnophilo's post did show the use of the boolean keywords?

You still add to to a an uninitialized variable, and you add to it regardless of what the comparison shows. An undefined number + 1 is still an undefined number. It would be undefined number + SIZE, if you would not call return inside the loop.


You don't seem (for whatever reason) able to pay attention to what we tell you.
I didn't mean to negate your responses, I am trying to balance multiple things at a time, I will reread my code and these responses and put together what I think is the correct code and re post it again here, as for the last remark my apologies again no need for the what seems to me rudeness. I appreciate the help you guys have given
"I have that code typed in but then what do I return?? Im confused because I cant return the array meet[i] can I?"

Why not? i is a local variable that just modifies which index meet[] points to, meet is not a local variable and you can assign it without having to return a value, or if you put it in a function you can pass it by reference. You are confusing the return statement which replaces the function call with a value produced by the function with an assignment operation which assigns a value to a variable. If a function says variable_x = 1; then variable_x will equal 1 until the function is finished executing if variable_x was declared in the function (or the initialization section of a loop) or it will still have the value assigned after the function/loop executes if variable_x was declared outside of the scope of the function/loop. The code I gave preserves the value of everything but variable i after the loop executes.

"after the true/false values get assigned to all of the indexes I need to tally up the true's and output that integer number."

So either make a loop that does that at the end or make another if-then statement that does numberoftrue++ or numberoffalse++ etc.
Last edited on
Thank you for baring with me on this, my apologies again. I will implement the code and come back with results
You're welcome, and no need to apologize, it's what the forum's here for. I am a newbie too (am about 3/4 of the way through the tutorial). Everything in programming is hard to comprehend at first, then it gradually becomes clearer. Sleeping on it helps a lot.
this is what I have after rereading this post.

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

using namespace std;

void displayHeader();
void readIntoSales(ifstream &fp, float Numsales, float sales[], float SIZE);
float computeAverage(ifstream &fp, float sales[], float SIZE, float Numsales);
int compareAboveArrays(float &Numsales,float sales[], float targetNumber[],bool meet[], float SIZE, float salesAverage, int sum);
float performanceInfo(float compareInfoBelow, float SIZE, float NumberOfFalses);
void displayResults(float totalAverage, float comparingInfoAbove, float infoPerformance);

int main()
{
  int NumberOfFalses = 0;
  float Numsales, salesInfo, totalAverage, results, comparingInfoAbove, infoPerformance, salesAverage;
  const int SIZE = 12;
  float targetNumber[] = {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 sales[SIZE];
  bool meet[SIZE];

  displayHeader();

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

  while(fp.eof()==false)
    {
      readIntoSales(fp, Numsales, sales, SIZE);
      totalAverage = computeAverage(fp, sales, SIZE, Numsales);
      comparingInfoAbove = (Numsales, targetNumber, sales, meet, SIZE, salesAverage, NumberOfFalses);
      infoPerformance = performanceInfo(comparingInfoAbove, SIZE, NumberOfFalses);
      displayResults(totalAverage, comparingInfoAbove, infoPerformance);
    }
return 0;
}

void displayHeader()
{

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

}


void readIntoSales(ifstream &fp, float Numsales, float sales[], float SIZE)
{
  fp >>Numsales;
  for (int i = 0; i < SIZE; i++)
    sales[i] = Numsales;

}


float computeAverage(ifstream &fp, float sales[], float SIZE, float Numsales)
{
  float sum = 0, salesAverage;
  for(int i = 0; i < SIZE; i++)
    {
      fp>>Numsales;
      sum += Numsales;
    }
  salesAverage = sum/SIZE;
  return salesAverage;
}

int compareAboveArrays(float &Numsales,float sales[], float targetNumber[], bool meet[], float SIZE, float &salesAverage, int NumOfFalses)
{
  int NumberOfFalses = 0;
  for (int i = 0; i < SIZE; i++)
    {
      if(sales[i] < targetNumber[i])
        meet[i] = false;
      else
        meet[i] = true;
 }
  for(int j = 0; j < SIZE; j++)
  if(meet[j] = false)
    NumberOfFalses++;
  else
    12 - NumberOfFalses;
  return NumberOfFalses;
}


float performanceInfo(float compareAboveArrays,float meet[], float SIZE, float &NumberOfFalses)
{
  string perform;
  for (int i = 0; i < SIZE; i++)
    if(NumberOfFalses  < 4 )
      perform = "satisfactory";
    else
      perform = "unsatisfactory";
  return perform;
}
float performanceInfo(float compareAboveArrays,float meet[], float SIZE, float &NumberOfFalses)
{
  string perform;
  for (int i = 0; i < SIZE; i++)
    if(NumberOfFalses  < 4 )
      perform = "satisfactory";
    else
      perform = "unsatisfactory";
  return perform;
}

    void displayResults(float totalAverage, float comparingInfoAbove,float infoPerformance)
{
  cout<<totalAverage << " " <<comparingInfoAbove <<infoPerformance <<endl;
}
I cant figure out the above and below part still and I have reread the post twice
What don't you understand?
how to tally then output the number of trues in the meet[] array. It reads if the current index of sales[] is < the current index of the targetNumber[], the current index gets false and else if sales[] is > targetNumber[]

but after that how do I tally the trues up and then output them?

do you get what im trying to say??

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
int compareAboveArrays(float &Numsales,float sales[], float targetNumber[], bool meet[], float SIZE, float &salesAverage, int NumOfFalses)
{
  int NumberOfFalses = 0;
  for (int i = 0; i < SIZE; i++)
    {
      if(sales[i] < targetNumber[i])
        meet[i] = false;
      else
        meet[i] = true;
 }
  for(int j = 0; j < SIZE; j++)
  if(meet[j] = false)
    NumberOfFalses++;
  else
    12 - NumberOfFalses;
  return NumberOfFalses;
}
Lets look at your code:
1
2
3
4
5
6
  int NumberOfFalses = 0;
  for(int j = 0; j < SIZE; j++)
  if(meet[j] = false)
    NumberOfFalses++;
  else
    12 - NumberOfFalses;

* You do initialize the counter before loop. That is good.
* You have only one statement in the loop body, so you do get away without braces {}. That is ok.
But,
* Line 3. meet[j] = false. Assignment. That expression sets every meet to false. Bad.
* Line 6. What? First a mysterious '12' that has nothing obvious to do with anything. Second, an expression, whose return value is not stored and which has no side effects. Third, if you are counting falses, then trues are insignificant.
1
2
3
4
5
6
7
count of falses is 0 at start.
For each item on list
  IF condition
  THEN update meet[item] to false and increase count
  ELSE update meet[item] to true

return count

You do have a lot of parameters to your function too. However, you only use sales, targetNumber, meet, and SIZE. Furthermore, you do modify only one of them, so the rest should be const. Is SIZE really a float?
I redid my functions for that part of my program because I was confusing myself as all get out. Agai nThank you for the great help and continuous responses. I was getting myself confused with all of the parameters and random variables I had initialized for no reason.

Here is what i have that I know works.

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

void booleanAssignments(float sales[], float target[], bool meet[], int SIZE)
{
  for(int i = 0; i < SIZE; i++)
    {
      meet[i];
      sales[i];
      target[i];

      if(sales[i] <= target[i])
        meet[i] = false;
      else
        meet[i] = true;
    }
}

//uses the bool array and finds how many months are above the standard
int compareAboveArray(bool meet[], int SIZE)
{
  int above = 0;

  for (int i = 0; i < SIZE; i++)
    {
      if(meet[i] == false)
         above++;
    }
  return above;
}

//uses the bool array and finds how many months are below the standard
int compareBelowArray(bool meet[], int SIZE)
{
  int below = 0;
  for (int i = 0; i < SIZE; i++)
    {
      if(meet[i] == true)
        below++;
    }
  return below;
Topic archived. No new replies allowed.
Pages: 12