I need some help with the output of my program and using arrays.
Here's the problem:
★★★★ Modify the program so that it outputs a list in order of number of pancakes eaten of all 10 people.
i.e.
Person 4: ate 10 pancakes
Person 3: ate 7 pancakes
Person 8: ate 4 pancakes
...
Person 5: ate 0 pancakes
I can't figure out how to use an array to display the person and the largest number in descending order. I'm almost positive that I have to use the same array in a for loop in conjunction with itself to get the people, but I'm stuck after that.
I've tried nesting a for loop within the for loop but that ended horribly.
#include <iostream>
usingnamespace std;
double panAverage(double avg, int total){ // calculates average of pancakes eaten
double average = 0;
average = total / avg;
return average;
}
int main()
{
constint avg = 10;
int pancakes[10], total = 0, average, max1 = 0, num = 0, max2;
for(int i = 1; i <= 10; i++){
cout << "How many pancakes did person [" << i
<< "] eat? ";
cin >> pancakes[num];
total += pancakes[num]; // gets total of pancakes
if (pancakes[num] > max1) // gets max pancakes
max1 = pancakes[num];
// I think using something like pancakes[i] would work to get the people but I'm not sure what to do next
}
cout << "There were a total of " << total << " pancakes eaten\n";
cout << "The average number of pancakes eaten was " << panAverage(avg, total) << endl;
cout << "The most pancakes that anyone ate was " << max1;
return 0;
}
I'll be honest, I don't quite understand. I was under the impression that the array pancakes can have no more than 10 integers...therefore [num] cannot count past 10.