我看到其他人就这个特定问题发布了问题,但有人可以看看我的解决方案吗?我用2个数组来解决它。不明白为什么吃煎饼最多的人没有反射(reflect)?它计算最大值,但不显示该人的号码。
#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;
}
最佳答案
这一行:
cout<<"Maximum number of pankakes is "<<max<<" eaten by person "<<people[i]<<endl;
是问题。到达它时,“i”将始终等于 5。您真正想要的是:
cout<<"Maximum number of pankakes is "<<max<<" eaten by person "<< person<<endl;
关于c++ - Pancake Glutton 任务 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34799926/