Hello everybody,
I am having trouble with the following. In my code, I don't get the right results for my getAverage/ getLeastAmount/ getGreatestAmount function. I don't know what I am doing wrong. Could anybody give me some hints, please?
#include <iostream>
#include <iomanip>
#include <cassert>
#include <fstream>
using namespace std;
const int monkey = 3;
const int days = 7;
int row=0;
int col=0;
void getInput(int FoodForMonkey[][days]);
void getTotal(int FoodForMonkey[][days]);
void getAverage (int FoodForMonkey[][days]);
void getLeastAmount (int FoodForMonkey[][days]);
void getGreatestAmount (int FoodForMonkey[][days]);
void InitializeArray (int FoodForMonkey[][days]);
int main()
{
int FoodForMonkey[monkey][days];
getInput (FoodForMonkey);
InitializeArray(FoodForMonkey);
getAverage (FoodForMonkey);
getLeastAmount (FoodForMonkey);
getGreatestAmount (FoodForMonkey);
system ("pause");
return 0;
}
//**************************************
void getInput(int FoodForMonkey[][days])
{
int input;
for (int row=0; row < monkey; row++)
{
for (int col=0; col < days; col++)
{
cout << "Monkey " <<row+1 <<" for day "
<< col+1 << " = ";
cin >> FoodForMonkey[row][col];
if (FoodForMonkey[row][col]<0)
{cout << "Amount of food cannot be negative. Try again."
<< endl;
return;}
} }
}
//**************************************
void InitializeArray(int FoodForMonkey[][days])
{
for (int row=0; row < monkey; row++)
{
for (int col=0; col < days; col++)
{
FoodForMonkey[row][col]=col+1;
}
}
}
//**************************************
void getAverage (int FoodForMonkey[][days])
{
for (int col=0; col < days; col++)
{
float numTotal=0;
cout << "Average amount eaten on day " << col+1;
for (int row=0; row < monkey; row++)
{
numTotal=numTotal + FoodForMonkey[row][col];
}
cout << " is " << float(numTotal/3) << endl;
}
}
//**************************************
void getLeastAmount (int FoodForMonkey[][days])
{
int leastAmount=0;
for (int row=0; row < monkey; row++)
{
//int leastAmount=0;
for (int col=0; col < days; col++)
{
if (FoodForMonkey[row][col] > FoodForMonkey[row][col+1])
leastAmount=FoodForMonkey[row][col];
}
cout << "Least amount consumed is " << leastAmount << endl;
}
}
//**************************************
void getGreatestAmount (int FoodForMonkey[][days])
{
int FoodForMonkey2[row][col];
FoodForMonkey2[row][col]= FoodForMonkey[monkey][days];
int greatestAmount;
for (int row=0; row < monkey; row++)
{
int greatestAmount=0;
for (int col=0; col < days; col++)
{
if (FoodForMonkey2[row][col] < FoodForMonkey2[row][col+1])
greatestAmount=FoodForMonkey2[row][col];
}
}
cout << "Greatest amount consumed is " << greatestAmount;
}
//**************************************