stuck storing a 2d 3 x 7 array & problems with logic

Hi guys im a new bee, im working on this assignment & I want to get how many pounds of food each of its 3 monkeys eats each day during a typical week. So, I have to write a program that stores the info in a two-dimensional 3 x 7 array. I also have to find the following:
•Average amount of food eaten per day by the whole family of monkeys
•The least amount of food eaten during the week by any one monkey
•The most amount of food eaten during the week by any one monkey


My errors are obviously the logic, when it compiles it only calulates does numbers of monkey #3. I will appreciate any help. Thanks.
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
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;


// Function prototypes
double AvgArray(double [], int);
double getHighest(double[], int);
double getLowest(double[], int);

int main(int argc, char *argv[])
{
    const int NUM_DAYS = 7; // Number of days
    const int NUM_MONKEYS = 3; //Number of monkeys
    double food[NUM_DAYS], 
    total,
    average,
    highest, 
    lowest;  
    
    

    
   cout << "\t\t\tMonkey Business" << endl;
   cout << endl;
   

   
   cout << " \tEnter the number of pounds eaten for monkey # 1\n";
   
   
  
   // Get the sales data
   for (int day = 0; day < NUM_DAYS; day++)
   {
         cout << " \tDay " << (day + 1) <<": ";
         cin >> food[day];
         average = total / NUM_DAYS;
   }
   
   cout << endl;
  
  cout << " \tEnter the number of pounds eaten for monkey # 2\n";
   
   
   for (int day = 0; day < NUM_DAYS; day++)
   {
         cout << " \tDay " << (day + 1) <<": ";
         cin >> food[day];
         average = total / NUM_DAYS;
   }
   
   cout << endl;
   
  cout << " \tEnter the number of pounds eaten for monkey # 3\n";
   
   for (int day = 0; day < NUM_DAYS; day++)
   {
         cout << " \tDay " << (day + 1) <<": ";
         cin >> food[day];
         average = total / NUM_DAYS;
   }
  
   // Get total
   total += AvgArray(food, NUM_DAYS);
   

   // Get highest and lowest lbs
   highest = getHighest(food, NUM_DAYS);
   lowest = getLowest(food, NUM_DAYS);
   average = AvgArray (food, NUM_DAYS);

   // Display results
    cout << fixed << showpoint << setprecision(2) << endl;
    
    cout << " \tThe total amount of food eaten per day by the" << endl;
    cout << " \twhole family of monkeys is: " << total << " lbs" << endl;
    cout << endl;
    
    cout << " \tThe average amount of food eaten per day by the" << endl;
    cout << " \twhole family of monkeys is: " << average << " lbs" << endl;
    cout << endl;
    
    cout << " \tThe most amount of food eaten during the week by" << endl; 
    cout << " \tany one monkey is: " << highest << " lbs" << endl;
    cout << endl;
    cout << " \tThe least amount of food eaten during the week by" << endl;
    cout << " \tany one monkey is: " << lowest << " lbs" << endl;
    cout << endl;
    
        
    system("PAUSE");
    return EXIT_SUCCESS;
}


//****************************************************
// Definition of AvgArray *
// This function computes and returns the sum of the *
// values in the double array passed to it. *
//****************************************************

 double AvgArray(double array[], int size)
{
   double total = 0; // Accumulator

   for (int count = 0; count < size; count++)
   total += array[count];
   return total;
   
}

  //*****************************************************
  // Definition of getHighest *
  // This function finds and returns the largest value *
  // in the double array passed to it. *
  //*****************************************************
   double getHighest(double array[], int size)
{
   double highest = array[0];

   for (int count = 1; count < size; count++)
   { 
       if (array[count] > highest)
       highest = array[count];
   }
   return highest;
}

//*****************************************************
// Definition of getLowest *
// This function finds and returns the smallest value *
// in the double array passed to it. *
//*****************************************************

    double getLowest(double array[], int size)
{
    double lowest = array[0];

    for (int count = 1; count < size; count++)
    { 
        if (array[count] < lowest)
        lowest = array[count];
    }
    return lowest;
}
The reason is because you only have a on dimensional array. You need to make it two dimensional...For example, this makes a 5x4 array:

double array[5][4];
It looks like you need to use nested for loops, otherwise it just thinks you are getting the info from one dimension of the array rather than the second dimension too.
so i nested it and it looks like this now:

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

cout << " \tEnter the number of pounds eaten for monkey # 1\n";
    for (int day = 0; day < NUM_DAYS; day++)
   {
        cout << " \tEnter the number of pounds eaten for monkey # 2\n";
          for (int day = 0; day < NUM_DAYS; day++)
          {
              cout << " \tEnter the number of pounds eaten for monkey # 3\n";
              for (int day = 0; day < NUM_DAYS; day++)
              {
                  for (int day = 0; day < NUM_DAYS; day++)
                  {
                      cout << " \tDay " << (day + 1) <<": ";
                      cin >> food[day];
                      average = total / NUM_DAYS;
                  }
              }
          }
   }
   






Topic archived. No new replies allowed.