Write a program that asks the user to enter the number of pancakes eaten for breakfast by 10 different people (Person 1, Person 2, ..., Person 10)
Once the data has been entered the program must analyze the data and output which person ate the most pancakes for breakfast.
Modify the program so that it also outputs which person ate the least number of pancakes for breakfast.
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 pancak
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
The first portion of this exercise was pretty easy, but is the second part that I need help with... this is not sorting, but printing the array in descending order, but keeping the index and value intact. Here's what I got so far.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
#include <iostream>
#include <string>
using namespace std;
int main()
{
int persons[10] = { 4, 5, 6, 2, 1, 4, 8, 9, 10, 20 };
for(int i = 0; i < 10; i++)
{
cout << "Enter how many pancakes person " << i << " ate: ";
cin >> persons[i];
}
//finding biggest and smallest
int small = persons[0], big = persons[0], idSmall, idBig;
for(int j = 0; j < 10; j++)
{
if(small > persons[j]) { small = persons[j]; idSmall = j; }
if(big < persons[j]) { big = persons[j]; idBig = j; }
}
cout << "The person who ate the most pancakes > " << idBig << endl;
cout << "The person who ate the least pancakes > " << idSmall << endl;
system("pause");
return 0;
}
|