Beginner Excercises Pancake glutton

I have been dong the Pancake glutton exercise from this page http://www.cplusplus.com/forum/articles/12974/

I've been at this for 45 minutes and can't figure out how to take the largest number from the numbers in array the user entered and display it. This is all I have so far

#include <iostream>
using namespace std;
int main () {
int person [10]; int num=0;
do {
cout<<"How many pancakes did person "<<num<<" eat: ";
cin>>person[num];
num++;
}
while (num!=10);
}


That code looks good so far, congratulations. The easiest way to find the largest number would be to use a for loop and loop through every location of your array. Have an int called max, and use an if statement within the for loop to check whether the current location of the array is smaller or larger than max. Have the program react accordingly.

ex: (Without giving the answer)
1
2
3
4
5
for(int i = 0; i < 10; i++)
{
     if(/*check the number of pancakes eaten here*/)
        //Number of pancakes is equal to the maximum
}
Thanks, I will give it a try
Topic archived. No new replies allowed.