and it keep saying person 2 ate the most pancake when other person ate more. I want to make program to print who ate the most pancake. So what do I need to change to make it work ?
First of all, the first element of p[10] is p[0] and not p[1], and the last element of p[10] is actually p[10];
declaring int p[10] means that you are declaring an array that contains 10 integers, of indexes going from 0 to 9.
If you assign a value to p[n] when n = 10 the compiler might not give you an error, but you have no idea where the value of p[10] will be written: it may overwrite some other variable.
int temp = p[0] //temp stores the max number of pancakes
for (int a=0;a<11;a++)
{
for (int b=0;b<11;b++)
{
if (p[a]>p[b])
{
temp = p[a];
}
}
}
for (int a=0;a<11;a++)
{
if (p[a] = temp)
{
cout << "Person " << p[a] << " ate the most pancakes\n" ;
}
}