//Ryan Shahriyarpour CS1A Carl Argila CH7 HW Question 4
//
/*****************************************************************************
*
* Monkey Business
*
*********************
*
* This program stores the pounds of food eaten by 3 monkeys over 7 days in a
* 3 x 7 array (rows = monkey and columns = days). It displays the average food
* eaten per day by all the monkeys, and the least and greatest amount eaten
* during the week by any one monkey
*
* INPUT
* Pounds of food eaten by each monkey on each day
*
* OUTPUT
* Average food per day, least and greatest weekly amount
* eaten by one monkey
****************************************************************************/
#include <iostream>
using namespace std;
const int MONKEYS = 3;
const int DAYS = 7;
int main()
{
double food[MONKEYS][DAYS];
double weekTotal;
double allTotal = 0;
double average;
double least;
double greatest;
// Input (no negative numbers allowed)
for (int m = 0; m < MONKEYS; m++)
{
for (int d = 0; d < DAYS; d++)
{
cout << "Monkey " << m + 1 << ", day " << d + 1 << " pounds: ";
cin >> food[m][d];
while (food[m][d] < 0)
{
cout << "Cannot be negative. Re-enter: ";
cin >> food[m][d];
}
}
}
// Total each monkey's week, then find the least and greatest
for (int m = 0; m < MONKEYS; m++)
{
weekTotal = 0;
for (int d = 0; d < DAYS; d++)
weekTotal = weekTotal + food[m][d];
allTotal = allTotal + weekTotal;
if (m == 0 || weekTotal < least)
least = weekTotal;
if (m == 0 || weekTotal > greatest)
greatest = weekTotal;
}
average = allTotal / DAYS;
// Output
cout << "\nAverage food per day (all monkeys): " << average << endl;
cout << "Least eaten by one monkey: " << least << endl;
cout << "Greatest eaten by one monkey: " << greatest << endl;
return 0;
}