// Andres Guzman CSC5 Chapter 7, P. 444, #4
/******************************************************************************
*
* CALCULATE MONKEY FOOD
* ____________________________________________________________________________
* This program will display the food intake of 3 monkeys and calculate their
* daily average consumption as a family, and find the highest and lowest
* intake amongst each monkey
*
* Computation
*
* total / (MONKEY * DAYS)
* ____________________________________________________________________________
*
* INPUT
* MONKEY = Size of rows
* DAYS = Size of Colomns
* week[MONKEY][DAYS] = Subscripts
* weeklytotal[MONKEY] = Subscript Accumulator
*
* OUTPUT
* highest = Displays highest amount of food eaten
* lowest = Displays lowest amount of food eaten
* total = accumulated total
*
******************************************************************************/
#include <iostream>
using namespace std;
int main()
{
const int MONKEY = 3; //Size of row
const int DAYS = 7; //Size of Colomns
int week[MONKEY][DAYS]; //Subscripts
int m; //counter for month
int d; //counter for days
double total = 0; //accumulator
double weeklytotal[MONKEY] = {0}; //subscript accumulator
//
//Initializing For Loop for subscript inputs in rows
for(m = 0; m < MONKEY; m++)
{
cout << "Monkey " << (m + 1) << " Weekly Consumption" << endl;
//
//Nested For Loop for colomns
for(d = 0; d < DAYS; d++)
{
cout << "Day " << (d + 1) << ": ";
cin >> week[m][d];
while(week[m][d] < 0) //Input Validation
{
cout << "Invalid Amount Eaten, Please Try Again.";
cout << "\nDay " << (d + 1) << ": ";
cin >> week[m][d];
}
total += week[m][d]; //Adds each weeks total to variable
weeklytotal[m] += week[m][d];//Adds week total to row subscript
cout << endl;
}
}
double highest = weeklytotal[0]; //Assigns subscript [0] to highest
double lowest = weeklytotal[0]; //Assigns subscript [0] to lowest
//
//Initializing For Loop
for (m = 0; m < MONKEY; m++)
{
if(weeklytotal[m] > highest) //Determines which subscript is
//greater than highest
{
highest = weeklytotal[m];//Assigns subscript to highest
}
if(weeklytotal[m] < lowest) //Determines which subscript is
//lower than lowest
{
lowest = weeklytotal[m];//Assigns subscript to lowest
}
}
cout << "Average Amount of Food Eaten: " << (total / (MONKEY * DAYS));
cout << "\nLeast Amount of Food Eaten during the Week: " << lowest << endl;
cout << "Most Amount of Food Eaten during the Week: " << highest << endl;
return 0;
}