I am having trouble with this array. I need to sort the second column in descending order. Please have a look and tell me where I went wrong. Much appreciated.
const int sizex=20;
const int sizey=2;
void descend(int arrayx[][sizey],int sizex,int sizey);
void printarray(int arrayx[][sizey],int sizex,int sizey);
int main()
{
int score[sizex][sizey];
const int sizex=20;
const int sizey=2;
int id, test;
for (int i=0; i<20; i++)
{id=rand()%90000+10000;
test=rand()%71+30;
score[i][0]=id;
score[i][1]=test;
cout<<"1 st: "<<score[i][0]<<" \t 2nd: "<<score[i][1]<<"\n";
}
descend(score, sizex, sizey);
return 0;
}
void printarray(int arrayx[sizex][sizey], int sizex, int sizey)
{
for(int i=0; i<=sizex-1; i++)
{for (int j=0; j<sizey-1; j++)
cout<<"Sorted 2nd: "<<arrayx[i][j]<<"\t";
cout<<"\n";
}
}
void descend(int arrayx[sizex][sizey], int sizex, int sizey)
{int temp[20][2];
for (int i=0; i<sizex; i++)
{for (int j=i+1; j<sizex; j++)
{if (arrayx[0][j]>arrayx[0][i])
{for(int k=0; k<sizex; k++)
{
{temp[i][k]=arrayx[j][k];
arrayx[j][k]=arrayx[i][k];
arrayx[i][k]=temp[i][k];
}
} cout<<"\n";
printarray(arrayx,sizex,sizey);
}
}
}
}