可能重复:
卡在 C++ 函数和数组上
卡在这个问题上:我无法让它运行,我坚持让数组函数返回到 main。谢谢你的帮助。
需要使用二维数组来存储 3 只猴子每周 7 天吃掉的食物磅数。
创建一个函数来获取一周中每一天每只猴子吃掉的磅数。创建第二个函数来确定通过数组来计算所有吃的钱的总数,然后是一天吃的平均值。
创建第三个函数来确定哪只猴子在哪一天吃的食物最少。还要输出猴子那天吃的量。创建第四个函数来确定哪只猴子一天吃的食物量最多。输出猴子数量、吃的磅数和工作日。
#include <iostream>
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;
double amount;
double amountEaten(double[] [weekdays], int);
double mostEaten (double[] [weekdays],int);
double leastEaten (double[][weekdays], int);
int main(){
double mostBananas (double[] [weekdays],int);
double leastBananas (double[][weekdays],int);
//double bananaAverage (double[][weekdays], int);
}
double amountEaten(double array[] [weekdays], int) {
cout << "Please enter the amount of food eaten per monkey per day." << endl;
double amount = array[0][0];
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 <<"Must feed positive amount" << endl;
}
}
}
double mostEaten( 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 leastEaten(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;
}