### Output Max

Hi, i did this program and now i want it to output the biggest value, someone can help me?
And please explain what you did, i want to know how to do.

 ``1234567891011121314151617181920`` ``````#include using namespace std; int main () { int x,n,pancakes[10]; for (n=0;n<10;n++) { cout << "Enter the amount of pancakes that person " << n << " ate: "; cin >> pancakes[n]; } getchar(); cout << "Who do you want to know how much pancakes ate?\nPerson: "; cin >> x getchar(); cout << "Person " << x << " ate " << pancakes[x]; getchar(); cout << "The person who ate most pancakes is "; getchar(); return 0; }``````
try this

 ``123456789101112`` ``````int largest = 0; for (int i = 0; i<10;i++) { if (pancakes[i] > largest) { largest = pancakes[i]; } }``````
Can you explain what you did?
 ``123456789101112`` ``````int largest = 0;//declare a variable to hold the largest number and set it to 0 for (int i = 0; i<10;i++) { if (pancakes[i] > largest)//if the first number in the array is larger than 'largest' make it the largest number { largest = pancakes[i]; //so every time a largest number is found in the array that number is sent to the 'largest' variable } }``````

that way the 'largest' variable will contain the largest number in the array once the for loop is done

hope that helps
Last edited on
:D thank you so much.
i'll see what i can do on my program :D
And if i want to know the person and not the amount?
What can i do to localize the person that have the larger value?
Topic archived. No new replies allowed.