#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int P[9],temp=0,g; //temp for highest pancakes, g for person number
for(int i=0;i<10;i++)
{
cout<<"Enter the number of pancakes eaten by person "<<i+1<<" ";
cin>>P[i];
if(P[i]>temp)
{
temp=P[i];
g=i+1;
}
}
cout<<"Most pancakes were ate by person "<<g<<endl<<temp;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
问题是如果我为最后一个人输入的值小于10,则循环再次开始.如果我输入P [9] <10,则循环再次运行.就像我输入0煎饼一样,下一个输出线是 - 输入人2吃的煎饼数量
但是,如果我输入一个大于10的值,那么循环似乎工作正常.问题出在这里?