# Arrays & Functions help

Page 1 of 1

## 1 Replies - 9351 Views - Last Post: 10 April 2009 - 10:49 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=98429&amp;s=2d328db0157ffdc2756ae0f90fe9ef8b&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Captain__stabin

Reputation: 0
• Posts: 18
• Joined: 06-March 09

# Arrays & Functions help

Posted 10 April 2009 - 09:04 AM

Assignment:
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 in a two-dimensional 3 x 7 array, where each row represents a monkey and each column represents a different day of the week. The program should first have the user input the data for each monkey. Then it should create a report (screen and file) that includes the following information:

•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 (out of all the monkeys)
•The most amount of food eaten during the week by any one monkey (out of all the monkeys)
Do not accept negative numbers for the amount of food eaten.

********** I have the average correct, but im having some trouble in the function finding the least amount and most amount of food eating during the week by any one monkey. I'll gladly appreciate any help guys. Thanks.
Here's what I've have so far :

```#include <cstdlib>
#include <iostream>
#include <iomanip>
using namespace std;

// Constants
const int MONKEYS = 3;
const int DAYS = 7;

//function prototypes
double familyAverage(const double mf[MONKEYS][DAYS]);
double littleMeal(const double mf[MONKEYS][DAYS]);
double bigMeal(const double mf[MONKEYS][DAYS]);

int main(int argc, char *argv[])
{

double monkey_table [MONKEYS][DAYS]={0};
int x, y;

cout << showpoint << fixed << setprecision(2) << endl;

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

for (x = 0; x < MONKEYS; x++)
{
for (y = 0; y < DAYS; y++)
{
do
{
cout << " \tEnter the number of pounds eaten for";
cout << " Monkey # " << x+1 << " ";
cout << " Day " << y+1 << ": ";
cin >> monkey_table [x][y];

if(monkey_table [x][y] < 0)
cout << "\t Please enter a positive number for pounds of food." << endl;

}
while(monkey_table [x][y] < 0);

}
cout << endl;

}

cout << "\t************************************************************" << endl;
cout << " \t\tThe average amount of food eaten per day" << endl;
cout << " \t\tby the whole family of monkeys ";
cout << " is " << familyAverage(monkey_table)<< " lbs" << endl;
cout << endl;

cout << " \t\tThe minimum amount of food eaten during" << endl;
cout << "\t\tthe week by any one monkey is " << littleMeal( monkey_table ) << " lbs" << endl;
cout << endl;

cout << "\t\tThe most amount of food eaten during the" << endl;
cout << "\t\tweek by any one monkey is " << bigMeal( monkey_table ) << " lbs" << endl;
cout << endl;

system("PAUSE");
return EXIT_SUCCESS;
}

double familyAverage(const double mf[MONKEYS][DAYS])
{
double total = 0;

for (int x = 0; x < MONKEYS; x++)
for (int y = 0; y < DAYS; y++)
total += mf[x][y];
total= (total / DAYS) / 3;

}

double littleMeal(const double mf[MONKEYS][DAYS])
{
double small= INT_MAX;

for (int x = 0; x < MONKEYS; x++)
for (int y = 0; y < DAYS; y++)
if (mf[x][y] < small)
small= mf[x][y];

return small;
}

double bigMeal(const double mf[MONKEYS][DAYS])
{
double big= 0;

for (int x = 0; x < MONKEYS; x++)
for (int y = 0; y < DAYS; y++)
if (mf[x][y] > big)
big= mf[x][y];

return big;
}

```

This post has been edited by Captain__stabin: 10 April 2009 - 09:06 AM

Is This A Good Question/Topic? 0

## Replies To: Arrays & Functions help

### #2 AndyH1963

Reputation: 22
• Posts: 201
• Joined: 22-June 08

## Re: Arrays & Functions help

Posted 10 April 2009 - 10:49 AM

It's good to see that you have posted your question to the correct forum, i.e. Homework. However, I have already answered in this post: