//Cameron Pham CS1A Chapter 7, p. 444, #2
//
/******************************************************************************
* TRACK MONKEY DIET
* ______________________________________________________________________________
* This program accepts a float value for how many pounds of food each of three
* monkeys eats each day for one week. It stores the data in a two-dimensional
* array and displays a report containing the average food eaten per day by the
* monkey family, as well as the least and greatest amounts eaten by any monkey.
* ______________________________________________________________________________
* INPUT
* Food // Pounds of food eaten by each monkey each day
*
* OUTPUT
* Average food // Average food eaten per day by the family
* Least food // Least food eaten by one monkey in a week
* Greatest food // Greatest food eaten by one monkey in a week
*******************************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
// Initialize variables
float food[3][7]; // Food eaten by 3 monkeys over 7 days
float totalFood = 0.0; // Total food eaten by all monkeys
float averageFood; // Average daily food eaten by the family
float leastFood; // Least food eaten by any monkey in a week
float greatestFood; // Greatest food eaten by any monkey in a week
// Store the names of the days of the week
string days[7] =
{
"Monday", "Tuesday", "Wednesday", "Thursday",
"Friday", "Saturday", "Sunday"
};
// Ask the user to enter food amounts for each monkey
for (int monkey = 0; monkey < 3; monkey++)
{
cout << endl << "Monkey #" << (monkey + 1) << endl;
for (int day = 0; day < 7; day++)
{
cout << "Enter pounds of food eaten on "
<< days[day] << ": ";
cin >> food[monkey][day];
// Validate the food amount
while (food[monkey][day] < 0)
{
cout << "Error: Food amount cannot be negative. ";
cout << "Enter the amount for " << days[day] << " again: ";
cin >> food[monkey][day];
}
// Add the amount to the weekly total
totalFood += food[monkey][day];
}
}
// Initialize the least and greatest food amounts
leastFood = food[0][0];
greatestFood = food[0][0];
// Find the least and greatest amounts eaten in a single day
for (int monkey = 0; monkey < 3; monkey++)
{
for (int day = 0; day < 7; day++)
{
if (food[monkey][day] < leastFood)
{
leastFood = food[monkey][day];
}
if (food[monkey][day] > greatestFood)
{
greatestFood = food[monkey][day];
}
}
}
// Calculate the average amount eaten per day by the monkey family
averageFood = totalFood / 7.0;
// Display the report
cout << fixed << setprecision(2);
cout << endl << "Monkey Business Report" << endl;
cout << "----------------------" << endl;
cout << "Average food eaten per day by the family: "
<< averageFood << " pounds" << endl;
cout << "Least amount eaten by single monkey in one day: "
<< leastFood << " pounds" << endl;
cout << "Greatest amount eaten by a single monkey in one day: "
<< greatestFood << " pounds" << endl;
return 0;
}