### Pancake glutton 4 stars last step

Hello, I have been coding with c++ for about 2-3 weeks now and I have been stuck with one exercise called "Pancake glutton" I need to collect answers from 10 people how many pancakes have they ate for breakfast and output answers in order with their respective number like that:

Person 4: ate 10 pancakes
Person 3: ate 7 pancakes
Person 8: ate 4 pancakes
...
Person 5: ate 0 pancakes

I have found a way how to put out the pancake amounts in decreasing order, but I still need to find out how to associate pancake amount with persons number.

I would appreciate help. Thank you.

 ``1234567891011121314151617181920212223242526272829303132333435363738`` `````` #include using namespace std; int main(){ int amount[10], number; for(number=0;number<=9;number++){ cout<<"How many pancakes does person # "<>amount[number]; } for(int a=0;a<=8;a++){ int temp; for(int b=a+1;b<=9;b++){ if(amount[a]>amount[b]){ temp=amount[a]; amount[a]=amount[b]; amount[b]=temp; } } } cout<
@JustinPlusPlus you should make a struct that can hold each person and their number of cancakes.

Here is an attempt to your problem.
 ``1234567891011121314151617181920212223242526272829`` ``````#include struct Person { int numberOfPancakes = 0; }; int main() { const int NUM_OF_PERSONS = 10; Person persons[NUM_OF_PERSONS]; std::cout << std::endl; for (int i = 0; i < NUM_OF_PERSONS; i++){ std::cout << "How many pancakes does person #" << (i + 1) << " eat ? "; std::cin >> persons[i].numberOfPancakes; } std::cout << std::endl << std::endl; for (int i = 0; i < NUM_OF_PERSONS; i++){ std::cout << "Person " << (i + 1) << " : ate " << persons[i].numberOfPancakes << " pancakes"<< std::endl; } std::cout << std::endl; return 0; }``````
Last edited on
Topic archived. No new replies allowed.