oh well, I'm afraid it isn't. here is the thing. first I create a for loop with "j" for listing some data. that data I want it to be in descending order from highest "sdmg" to lowest "sdmg" the tricky part is that I want to "memorise" the "sname" for each one of them and list not only the numbers in descending order, but the numbers with their corresponding names...
ok let's say I enter some data there... 4 names and some other data that makes 4 numbers. let's say...
Andy has the number 85
Zack has the number 96
Chriss has the number 34
Alex has the number 36
so... I want to list them like this:
1. Zack - 96
2. Andy - 85
3. Alex - 36
4. Zack - 34
btw you're not dense; if you don't understand something, it's the one who tried to explain's fault
EDIT: I think I got it... I was complicating too much tryint not to change the variable's values... but I think I'll try the bubble loop and change both the sdmg and the sname at the same time... I'll tell you if I succeeded
EDIT2: I made this bubble sort:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
void sort(float arr1 [], string arr2 [], int size)
{
int temp1;
string temp2;
for (int i = 0; i <= size; i++)
{
for (int j = 0; j <= size - 1; j++)
{
if (arr1[j] > arr1[j + 1])
{
temp1 = arr1[j];
arr1[j] = arr1[j + 1];
arr1[j + 1] = temp1;
temp2 = arr2[j];
arr2[j] = arr2[j + 1];
arr2[j + 1] = temp2;
}
}
}
}
|
with
1 2 3 4 5 6
|
sort(sdmg, sname, i);
for (int j = 0; j <= i; j++)
{
cout << j + 1 << ". " << sname[j] << " - " << sdmg[j] << endl;
}
|
in main function...
this way I can swap both the sdmg and it's corresponding names. it worked pretty well I can tell! but something is still not right though... it's in ascending order :| not descending. how can I make it to be in descending order, please?
EDIT3: I managed to make everything to work! ^_^
changed
1 2 3 4
|
for (int j = 0; j <= i; j++)
{
cout << j + 1 << ". " << sname[j] << " - " << sdmg[j] << endl;
}
|
into
1 2 3 4
|
for (int j = i; j >= 0; j--)
{
cout << i - j + 1 << ". " << sname[j] << " - " << sdmg[j] << endl;
}
|
and it's sorted just like I wanted ^_^ thank you very much for your help; and I hope I helped everyone else who read this topic ^_^