我见过其他人就这个问题发布了问题,但有人可以看一下我的解决方案吗?我用2个数组来解决它。我不明白为什么吃过最多煎饼的人没有被反映出来?它计算最大值,但不显示此人的号码。
#include <iostream>
using namespace std;
int main() {
int array_numbers[5];
int people[5] = { 1, 2, 3, 4, 5 };
int i, max = -1, person = -3;
for (i = 0; i < 5; i++) {
cout << "Enter how many pankakes person "
<< people[i] << " has eaten for dinner\n";
cin >> array_numbers[i];
if (array_numbers[i] > max) {
max = array_numbers[i];
person = people[i];
}
}
cout << "Maximum number of pankakes is "
<< max << " eaten by person "
<< people[i] << endl;
return 0;
}
答案 0 :(得分:1)
这一行:
cout<<"Maximum number of pankakes is "<<max<<" eaten by person "<<people[i]<<endl;
是问题所在。到达时,'我'将始终等于5.你真正想要的是:
cout<<"Maximum number of pankakes is "<<max<<" eaten by person "<< person<<endl;