Need Help with Arrays

I just need help storing the information in rows and columns. Here is the description:
"A local zoo wants to keep track of how many pounds of food each of its three monkeys eats each day during a typical week. Write a program that stores this information on a two-dimensional 3 x 7 array, where each row represents a different monkey and each column represents a different day of the week. The program should first have the user input the data for each monkey"

And here's what I've got so far:
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
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
    double totalAverage =0;
    int monkey = 0, day = 0;
    int entered_value;


    const int NUM_MONKEYS = 3;
    const int NUM_DAYS = 7; 
    double average [NUM_MONKEYS][NUM_DAYS];
    double highest = 0, lowest;
    double monkeys[NUM_MONKEYS];

    memset(&monkeys[0], 0, sizeof(monkeys));
    memset(&average[0], 0, sizeof(average));

    cout << "Enter the amount of food in pounds eaten by the referred monkey.\n";

    for (monkey = 0; monkey < NUM_MONKEYS; monkey++)
    {
        for (day = 0; day < NUM_DAYS; day++)
        {
            cout << "Monkey " << (monkey + 1) << ", "
            << "Day " << (day + 1) << ": ";
            cin >> average [monkey][day];
            while ((average [monkey][day] < 0))
            {
                // Ensure that negative numbers are not accepted.
                entered_value = -1;
                while (entered_value < 0)
                {
                    cout << "Please enter positive values.\n";
                    cin >> entered_value;
                    if (entered_value > -1)
                    {
                        average [monkey][day] = entered_value; 
                    }
                    else
                    {
                        cout << "Negative values are not accepted.\n";
                    }
                }
            }
        }
        cout << endl;
    }

    for (monkey = 0; monkey < NUM_MONKEYS; monkey++)
    {
        // Get the total amount of food eaten during the week
        for (day =0; day< NUM_DAYS; day++)
        {
            // Store the total amount eaten by each monkey
            monkeys[monkey] += average [monkey][day];
        }
    }

    // Compute the average amount eaten by all monkeys each day.
    totalAverage = monkeys[0] + monkeys[1] + monkeys[2];
    totalAverage =  totalAverage / NUM_DAYS;

    // Compare the amounts eaten by each monkey to determine which one ate the most.
    for (monkey = 0; monkey < NUM_MONKEYS - 1; monkey++)
    {
        if (monkeys[monkey] > monkeys[monkey + 1])
        {
            if (monkeys[monkey] > highest)
            {
                highest = monkeys[monkey];
            }
        }
        else
        {
            highest = monkeys[monkey + 1];
        }
    }

    if (monkeys[0] < monkeys[1] && 
        monkeys[0] < monkeys[2])
    {
        lowest = monkeys[0];
    }
    else if (monkeys[1] < monkeys[2]) 
    {
        lowest = monkeys[1];
    }
    else
    {
        lowest = monkeys[2];
    }

    cout << fixed << showpoint << setprecision (2); // DOUBLE
    cout << "The average amount is: " << totalAverage << endl;
    cout << "The highest amount is: " << highest << endl;
    cout << "The lowest amount is: " << lowest << endl; 


    system ("PAUSE");
    return 0;
}
what is your current output? What do you expect to get as valid output?
closed account (48T7M4Gy)
Delete lines 18 and 19 and the program runs. What is their use/significance?

I haven't checked the output but this is what I got. Given the highest and lowest which are per monkey per week I assume, the average is a bit suspect.

Enter the amount of food in pounds eaten by the referred monkey.
Monkey 1, Day 1: 2
Monkey 1, Day 2: 2
Monkey 1, Day 3: 3
Monkey 1, Day 4: 4
Monkey 1, Day 5: 5
Monkey 1, Day 6: 6
Monkey 1, Day 7: 6

Monkey 2, Day 1: 2
Monkey 2, Day 2: 6
Monkey 2, Day 3: 5
Monkey 2, Day 4: 3
Monkey 2, Day 5: 9
Monkey 2, Day 6: 2
Monkey 2, Day 7: 2

Monkey 3, Day 1: 2
Monkey 3, Day 2: 3
Monkey 3, Day 3: 3
Monkey 3, Day 4: 2
Monkey 3, Day 5: 4
Monkey 3, Day 6: 8
Monkey 3, Day 7: 2

The average amount is: 11.57
The highest amount is: 29.00
The lowest amount is: 24.00
Last edited on
Topic archived. No new replies allowed.