I need help starting my C++ HW assignment.

How would I start this program off?

Step 1)

Declare 2 global constants: NUM_ MONKEYS = 3;
NUM_DAYS = 7;

In main, declare a one-dimensional string array that will hold the names of 3 monkeys. (make up your own names for your monkeys and be creative..you may not use mine!)

In main, declare a 2 dimensional array that will hold the amount of food (in pounds) that each of the three monkeys have eaten in a period of 7 days. **Be sure to use my test data.

Step 2)

Fill the arrays

Declare the 2 arrays (1 dim for 3 names, 2 dim for food), initialize the arrays with the data to be used in the project. Use my data (see the next page).

Step 3)

Create a function that prints the contents of the two arrays in this format:

Name Day 1 Day 2 Day 3 Day 4 Day 5 Day 6 Day 7
Bonnie 45 33 55 66 77 88 100
Clyde 88 77 66 55 44 33 22
Trigger 44 55 11 66 77 88 99

In the function heading, declare both arrays as constant arrays.
Format as closely as possible, but don’t obsess too much over perfection.

Step 4)
Create a function that calculates and displays the average daily food intake for each of the three monkeys. In that function, display the averages with one number to the right of the decimal point. Report the results in the following format:
Name Average daily intake in pounds
Bonnie (report the results)
Clyde etc.
Trigger etc.

In the function heading, declare both arrays as constant arrays.

Step 5)
Create a function that determines the one monkey who ate the least amount of food. Output the results in that function using the following format:
Least amount of food: _Monkey # _ ate ____ pounds on Day # _____

In the function heading, declare both arrays as a constant arrays.

Extra Credit: +1 point for placing the monkey name in the output above.


Step 6)
Create a function that determines the one monkey who ate the most amount of food. Output the results in that function using the following format:
Most amount of food: _Monkey # __ ate ____ pounds on Day # _____

In the function heading, declare both arrays as a constant arrays.

Extra Credit: +1 point for placing the monkey name in the output above.
You'd start by doing what you've been asked to do. I'll help with part of step 1.
1
2
3
4
5
6
7
const int NUM_ MONKEYS = 3;
const int NUM_DAYS = 7;

int main()
{
  std::string monkeys[3];
}
@BJ19

I'll finish off the help of step 1 started by kbw..

1
2
3
4
5
6
7
8
const int NUM_MONKEYS = 3;
const int NUM_DAYS = 7;

int main()
{
  std::string monkeys[NUM_MONKEYS];
  std::int monkey_food[NUM_MONKEYS][NUM_DAYS];
}
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
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;

const int NUM_MONKEYS = 3;
const int NUM_DAYS = 7;
void showData(string monkeys[NUM_MONKEYS],int table[][NUM_DAYS]);
void calculateDailyIntake(string monkeys[NUM_MONKEYS], int table[][NUM_DAYS]);

int main()
{
    // 1-D array to hold monkeys names
    string monkeys[NUM_MONKEYS] = { "Louie", "Bo-Bo", "Jimmy" };
    
    int table[NUM_MONKEYS][NUM_DAYS] = { { 45,33,55,66,77,88,100 },
        { 88,77,66,55,44,33,22 },
        { 44,55,11,66,77,88,99 }};
  
    showData(monkeys, table);
    calculateDailyIntake(monkeys,table);

    system("pause");
    return 0;
    
}


// "prints the contents of the two arrays"
void showData(string monkeys[NUM_MONKEYS], int table[][NUM_DAYS])
{
    cout << "Name \t\tDay 1\tDay 2\tDay 3\tDay 4\tDay 5\tDay 6\tDay 7   " << endl;
    cout << "_________________________________________________________________\n";
    for (int r = 0; r < NUM_MONKEYS; r++)
    {
        cout << monkeys[r];
        for (int c = 0; c < NUM_DAYS; c++)
        {
            cout << "\t\t";
            cout << table[r][c];
        }
        cout << endl;
    }
    cout << endl;
}


// "calculate and display the average daily food intake for each of the three monkeys"
void calculateDailyIntake(string monkeys[NUM_MONKEYS], int table[][NUM_DAYS])
{
    cout << "Name \t\tAverage daily intake in pounds \n";
    cout << "_________________________________________________________________\n";
    double totalRow = 0;
    cout << setprecision(1) << fixed;
    
    for(int r = 0; r < NUM_MONKEYS; r++)
    {
        for(int c = 0; c < NUM_DAYS; c++)
            
        totalRow = totalRow + table[r][c];
        
        cout << monkeys[r] << "\t" << setw(1) << (totalRow/NUM_DAYS) << endl;
    }
    totalRow = 0;
}
    
@kbw

My average is not printing out right. This is what I am getting:

Name Day 1 Day 2 Day 3 Day 4 Day 5 Day 6 Day 7
_________________________________________________________________
Louie 45 33 55 66 77 88 100
Bo-Bo 88 77 66 55 44 33 22
Jimmy 44 55 11 66 77 88 99

Name Average daily intake in pounds
_________________________________________________________________
Louie 66.3
Bo-Bo 121.3
Jimmy 184.1
The average for louie is correct but not for Bo-Bo and Jimmy.
@BJ19

Between lines 57 and 58, add totalRow = 0;

You are adding ALL the numbers and getting an average, which is not what you want.
@whitenite1

may you help me complete step 5 & 6?
@BJ19

For #5
Create a function, like void Least(string monkeys[NUM_MONKEYS], int table[][NUM_DAYS])
Create an int to hold value of 0 for the monkey number, and int to hold value of food eaten, and a third one, for the day. Give the food variable a value of maybe 1000, or at least higher than any food amount in the array.

Do a double loop, 0 to NUM_MONKEYS and 0 to NUM_DAYS and check if the value in that part of the array is LOWER than the food value. If yes, let the food value equal the lower amount, assign the day variable to the value in the NUM_DAYS loop and also assign the monkey number to the value in the NUM_MONKEYS loop.
When finished, you can cout << "Least amount of food: Monkey # << monkey_number
<< ", "<< monkeys[monkey_number]<< ", ate " << food eaten << " pounds on Day #"
<< day".

For #6, do the same, but check for values that are HIGHER for food eaten, and then change the values for day and monkey number. Of course, use a different function, like void Most(string monkeys[NUM_MONKEYS], int table[][NUM_DAYS]).

Hope this helps you.
Topic archived. No new replies allowed.