Mar 16, 2012 at 7:41pm UTC
Im looking for the largest and smallest from the array but the results are 0.00 for smallest and the last user input for largest. Can anyone help me find the reason for this?
thank you,
# include <iostream>
# include <iomanip>
using namespace std;
const int Monkeys = 3;
const int WeekDays = 7;
double monkeyWeek[Monkeys] [WeekDays];
double largest;
double least;
double average;
int index;
int dayCount;
int main()
{
double mostBananas (double[] [WeekDays],int);
double leastBananas (double[][WeekDays],int);
double bananaAverage (double[][WeekDays], int);
cout << "Please enter the amount of food eaten per monkey per day." << endl;
for (index = 0; index < Monkeys; index++)
{
for (dayCount = 0; dayCount < WeekDays; dayCount++)
{
cout << endl <<"Please enter the amount of pounds eaten by monkey"<<(index +1);
<< endl << "for day " << (dayCount +1) << ": ";
cin >> monkeyWeek[Monkeys] [WeekDays] ;
if (monkeyWeek[Monkeys] [WeekDays] < 1)
cout << endl <<"Please don't starve your monkeys." << endl;
}
}
cout << fixed << showpoint << setprecision(2) << endl;
largest = mostBananas(monkeyWeek,WeekDays);
cout << largest << endl;
least = leastBananas(monkeyWeek,WeekDays);
cout << least << endl;
system("PAUSE");
}
double mostBananas( double array[] [WeekDays], int size)
{
double largest = array[0][0];
for (int count = 0; count < size; count++)
{
for (int col = 0; col < count; col++)
{
if (array[count][WeekDays] > largest)
largest = array[count][WeekDays];
}
}
return largest;
}
double leastBananas(double array[] [WeekDays], int size)
{
double least = array[0][0];
for (int count = 0; count < size; count++)
{
for (int col = 0; col < size; col++);
{
if (array[count][WeekDays] < least)
least = array[count][WeekDays];
}
}
return least;
}