Académique Documents
Professionnel Documents
Culture Documents
#include <iomanip>
using namespace std;
// constants
const int MONKEYS = 3;
const int DAYS = 7;
// function prototype.
void getFood(double arr[][DAYS], int rows);
void avgFood(double arr[][DAYS], int rows);
void leastAmount(double arr[][DAYS], int rows);
void greatestAmount(double arr[][DAYS], int rows);
int main()
{
// declarations.
double food[MONKEYS][DAYS];
// header
cout << "\tMonkey Business :::\n\n";
cout << "Enter the food each monkey eats (in pounds) during the week
.\n\n";
// get food.
getFood(food, MONKEYS);
cout << "Report:\n";
cout << "----------------------\n";
// get average.
avgFood(food, MONKEYS);
// get least amount in that week.
leastAmount(food, MONKEYS);
// get greatest amount in that week.
greatestAmount(food, MONKEYS);
system("pause");
// End program.
return 0;
}
// getFood function
// Takes three arguments. It asks the user to enter the food in
// pounds that each monkey eats, for every day in a single week.
void getFood(double arr[][DAYS], int rows)
{
for (int nRows = 0; nRows < rows; nRows++)
{
cout << "Monkey " << (nRows + 1) << "\n";
for (int nCols = 0; nCols < DAYS; nCols++)
{
cout << " Day " << (nCols + 1) << ": ";
cin >> arr[nRows][nCols];
// validate.
while (arr[nRows][nCols] < 0)
{
cout << "ERROR: food cannot be lower than 0,
try again: ";
int day = 0;
// accumulator.
for (int nCols = 0; nCols < DAYS; nCols++)
{
if (arr[nRows][nCols] > greatest)
{
greatest = arr[nRows][nCols];
day += (nCols + 1);
}
}
cout << "On day " << day;
cout << " monkey " << (nRows + 1);
cout << " ate the greatest amount of food.\n";
}
// empty line
cout << endl;
}