You will be using arrays to track the food intake of 3 adorable monkeys for one week. After filling a 1 dimension with monkey names and a 2 dimension array with food data, you will calculate and report very important statistics about the monkeys.
In main, declare a one-dimensional string array that will hold names of 3 monkeys. 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.
Declare the name array, initializing the array with the word “none” for all three names.
Declare the 2 dim array using 0 as the initial values for all 21 days.
Call a function and use a loop to ask the user for the monkey’s names.
In the same function, ask the user for the pounds of food eaten by each of the 3
monkeys for the seven days.
Create a function that calculates and displays the average daily food intake for each of the three monkeys
Create a function that determines the one monkey who ate the least amount of food.
Create a function that determines the one monkey who ate the least amount of food.
So for my output doesn't show which monkey ate the least or most amount of food. It doesn't show the average of each monkey either, instead only shows total average.
{
double total = 0.0;
for (int monkey = 0; monkey < NUM_MONKEYS; monkey++)
{
for (int day = 0; day < NUM_DAYS; day++)
total += food[monkey][day];
}
return total;
}
/*****************************************************
* findOneTotal *
* Finds and returns the amount of food eaten during *
* the week by one particular monkey. It does this by*
* totaling and returning the values in the one row *
* of the array representing the desired monkey. *
// Set leastTotal to the first monkey's total food consumption
leastTotal = findOneTotal(food, 0);
// Check if any other monkey consumed less food
for (int thisMonkey = 1; thisMonkey < NUM_MONKEYS; thisMonkey++)
{
thisMonkeyTotal = findOneTotal(food, thisMonkey);
if (thisMonkeyTotal < leastTotal)
leastTotal = thisMonkeyTotal;
}
return leastTotal;
}
/*****************************************************
* findGreatestTotal *
* Finds and returns the largest row total. *
*****************************************************/
double findGreatestTotal(double food[][NUM_DAYS])
{
double thisMonkeyTotal;
double greatestTotal;
// Set greatestTotal to the first monkey's total food consumption
greatestTotal = findOneTotal(food, 0);
// Check if any other monkey consumed more food
for (int thisMonkey = 1; thisMonkey < NUM_MONKEYS; thisMonkey++)
{
thisMonkeyTotal = findOneTotal(food, thisMonkey);
if (thisMonkeyTotal > greatestTotal)
greatestTotal = thisMonkeyTotal;
}
You have to divide by NUM_DAYS to get the relevant average. You only do this for the first output (all monkeys). You don't do it for the other two, which therefore give you totals, not averages.
Please use code tags and indentation to make your code readable.