Original Post
I have been working on this problem for a while.I am working on writing a program that asks the user to enter the number of pancakes eaten for breakfast by 10 different people. My question how do I modify this program so that it outputs a list in order of number of pancakes eaten by all 10 people. I am using a bubble sort to sort the array of values.I also want to output which person ate the least and most number of pancakes, which I have figured out.
I want the program to output the following list.
Person 4: ate 10 pancakes.
Person 3: ate 7 pancakes.
Person 8: ate 4 pancakes.
...
Person 5: ate 0 pancakes.
Here is the code I am using.
[source lang =c++]
#include
#include
using namespace std;
int array[10];
int main()
{
for(int i=0;i< 10;i++)
{
cout << "Enter number of pancakes eaten: ";
cin >> array;
}
for(int i=0; i<10; i++)
{
for(int j=0;j {
if(array {
int temp = array;
array=array[j];
array[j]=temp;
}
}
}
int size=10;
int position = 0;
int result = -1;
int target=array[9];
while(result==-1 && position < size)
{
if(array[position] == target)
{
result = position;
}
position++;
}
cout << endl;
cout << "Person " << result << " ate " << array[result] << " the most pancakes." << endl;
cout << endl;
size=10;
position=0;
result = -1;
target = array[0];
while(result==-1 && position < size)
{
if(array[position] == target)
{
result = position;
}
position++;
}
cout << endl;
cout << "Person " << result << " ate " << array[result] << " the least pancakes." << endl;
cout << endl;
for (int j=0; j< 10; j++)
{
cout << "Person " << j << " ate " << array[j] << " pancakes." << endl;
}
int test;
cin >> test;
return 0;
}
[/source]
I want the program to output the following list.
Person 4: ate 10 pancakes.
Person 3: ate 7 pancakes.
Person 8: ate 4 pancakes.
...
Person 5: ate 0 pancakes.
Here is the code I am using.
[source lang =c++]
#include
#include
using namespace std;
int array[10];
int main()
{
for(int i=0;i< 10;i++)
{
cout << "Enter number of pancakes eaten: ";
cin >> array;
}
for(int i=0; i<10; i++)
{
for(int j=0;j {
if(array
int temp = array;
array=array[j];
array[j]=temp;
}
}
}
int size=10;
int position = 0;
int result = -1;
int target=array[9];
while(result==-1 && position < size)
{
if(array[position] == target)
{
result = position;
}
position++;
}
cout << endl;
cout << "Person " << result << " ate " << array[result] << " the most pancakes." << endl;
cout << endl;
size=10;
position=0;
result = -1;
target = array[0];
while(result==-1 && position < size)
{
if(array[position] == target)
{
result = position;
}
position++;
}
cout << endl;
cout << "Person " << result << " ate " << array[result] << " the least pancakes." << endl;
cout << endl;
for (int j=0; j< 10; j++)
{
cout << "Person " << j << " ate " << array[j] << " pancakes." << endl;
}
int test;
cin >> test;
return 0;
}
[/source]