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.
Thanks in advance,
#include <iostream>
usingnamespace 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;
}
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