//Xinnuo Wang CS1A chapter7 #4
/*******************************************************************************
* Display Amount of Food
* _____________________________________________________________________________
* The program accepts pounds of food each of its three monkeys eats each day
* during a typical week and diaplays 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 and the greatest amount of food eaten during the week by
* any one monkey.
*
* _____________________________________________________________________________
* Input:
* food : The accepted amount of food of different monkey in the dimentional array.
* Output:
* ave : Average amount of food eaten per day by the whole family of monkeys.
* Largest : The greatest amount of food eaten during the week by any one monkey.
* Smallest : The least amount of food eaten during the week by any one monkey.
*
* ****************************************************************************/
#include <iostream>
using namespace std;
int main()
{
double food[3][7];
double monkey[3];//The amount of food eaten during the week by any one monkey.
double sum = 0, ave = 0;
double Largest = 0;
double Smallest = 0;
for (int r = 0; r < 3; r++)
{
for (int c = 0; c< 7; c++)
{
cout << "Enter amount of food of the monkey "<< (r+1)<< " on day ";
cout << (c + 1);
cin >> food[r][c];
cout << food[r][c]<< endl;
//validate check
while(food[r][c] < 0)
{
return 0;
}
sum +=food[r][c];
monkey[r]+=food[r][c];
}
}
ave = sum / 7;
Largest = monkey[0];
Smallest =monkey[0];
for(int i = 0; i < 3; i++ )
{
if (Largest < monkey[i])
Largest = monkey[i];
if (Smallest > monkey[i])
Smallest= monkey[i];
}
// OUTPUT RESULT
cout << "Average amount of food eaten per day by the whole family of monkeys";
cout<< "is: " << ave << endl;
cout << "The least amount of food eaten during the week by any one monkey is";
cout<< ": " << Smallest << endl;
cout << "The greatest amount of food eaten during the week by any one monkey ";
cout << "is: " << Largest << endl;
return 0;
}