pancakes exercise problem :P

I want to cout the list starting from the person who ate most pancakes and finishing with the person who ate least.
but it doesn't work :P




#include <iostream>

int main ()
{
using namespace std;

int x;
int pancakes[10];



for (x=0;x<10;x++)
{
cin >> pancakes[x];

}



int order[10];
int i,j,m;


for (i=0; i<10; i++)

{

m=-5;

for (j=0+i;j<10;j++)
{




if (pancakes[j]>m)
{
m=pancakes[j];

}
order[i]=m;


}




int p;
for (p=0;p<10;p++)
{

cout << "Person number" << (p+1) << "ate :" << order[p] << "pancaakes" << endl;
}







}
return 0;


}
Here's your sorting for loop:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int order[10];
int i,j,m;

for (i=0; i<10; i++){
    m=-5;
    for (j=0+i;j<10;j++){
        if (pancakes[j]>m){
            m=pancakes[j];
        }
        order[i]=m;
    }

    int p;
    for (p=0;p<10;p++){
        cout << "Person number" << (p+1) << "ate :" << order[p] << "pancaakes" << endl;
    }
}

I have no idea why would you put output there, su I assume you meant
1
2
3
4
5
6
7
8
9
10
11
12
int order[10];
int i,j,m;

for (i=0; i<10; i++){
    m=-5;
    for (j=0+i;j<10;j++){
        if (pancakes[j]>m){
            m=pancakes[j];
        }
        order[i]=m;
    }
}

This is not sorting. This code sets order[i] to the highest value in range from pancakes[i] to pancakes[10]. So if input array was 0 1 2 3 4 5 6 7 8 9, the output would be 9 9 9 9 9 9 9 9 9 9.
see http://en.wikipedia.org/wiki/Bubble_sort or some other algorithm. Or http://www.cplusplus.com/reference/algorithm/sort/ if you're lazy..
Topic archived. No new replies allowed.