Hey guys working on an assignment called monkey business and here is my code im getting an error on these two things.
Error:
cout << "Monkey number " << (monkey + 1)
<< " ate the least amount of food,\n"
<< leastFood << " pounds, on day "
<< (leastDay + 1) << endl;
}
cout << "Monkey number " << (monkey + 1)
<< " ate the most amount of food,\n"
<< mostFood << " pounds, on day "
<< (mostDay + 1) << endl;
}
// Chapter 7, Programming Challenge 4
// Monkey Business
#include<iostream>
#include <iomanip>
using namespace std;
const int MONKEYS = 3;
const int DAYS = 7;
void getFoodEaten(double [][DAYS]);
void displayAverageDaily(double [][DAYS]);
void displayLeastEaten(double [][DAYS]);
void displayMostEaten(double [][DAYS]);
int main()
{
double food[MONKEYS][DAYS];
getFoodEaten(food);
displayAverageDaily(food);
displayLeastEaten(food);
displayMostEaten(food);
return 0;
}
void getFoodEaten(double food[][DAYS])
{
for (int monkey = 0; monkey < MONKEYS; monkey++)
{
for (int day = 0; day < DAYS; day++)
{
cout << "Enter the pounds eaten by monkey "
<< "number " << (monkey + 1)
<< "\non day " << (day + 1) << ": ";
cin >> food[monkey][day];
while (food[monkey][day] < 0)
{
cout << "Enter a non-negative amount: ";
cin >> food[monkey][day];
}
}
}
}
void displayAverageDaily(double food[][DAYS])
{
double total;
double average;
for (int day = 0; day < DAYS; day++)
{
total = 0.0;
for (int monkey = 0; monkey < MONKEYS; monkey++)
{
total += food[monkey][day];
}
average = total / MONKEYS;
cout << "The average amount eaten on day "
<< (day + 1) << " is " << average
<< " pounds.\n";
}
}
void displayLeastEaten(double food[][DAYS])
{
double leastFood;
int leastMonkey;
int leastDay;
leastMonkey = 0;
leastDay = 0;
leastFood = food[leastMonkey][leastDay];
for (int monkey = 0; monkey < MONKEYS; monkey++)
{
for (int day = 0; day < DAYS; day++)
{
if (food[monkey][day] < leastFood)
{
leastFood = food[monkey][day];
leastDay = day;
leastMonkey = monkey;
}
}
}
cout << "Monkey number " << (monkey + 1)
<< " ate the least amount of food,\n"
<< leastFood << " pounds, on day "
<< (leastDay + 1) << endl;
}
void displayMostEaten(double food[][DAYS])
{
double mostFood;
int mostMonkey;
int mostDay;
mostMonkey = 0;
mostDay = 0;
mostFood = food[mostMonkey][mostDay];
for (int monkey = 0; monkey < MONKEYS; monkey++)
{
for (int day = 0; day < DAYS; day++)
{
if (food[monkey][day] > mostFood)
{
mostFood = food[monkey][day];
mostDay = day;
mostMonkey = monkey;
}
}
}
cout << "Monkey number " << (monkey + 1)
<< " ate the most amount of food,\n"
<< mostFood << " pounds, on day "
<< (mostDay + 1) << endl;
}