Getting lowest number and storing it in a variable -
iTorran - 02.05.2012
I have a set of 8 numbers..
I need to get the lowest and store it into a variable.. lets call it first.
After that I need to get the second lowest and store that into another variable.. lets call it second..
I need to do it again and again for 8 variables..
Code:
Lowest = variable: first
2nd Lowest = variable: second
3rd Lowest = variable: third
4th Lowest = variable: fourth
5th Lowest = variable: fifth
6th Lowest = variable: sixth
7th Lowest = variable: seventh
8th Lowest = variable: eighth
Like that.. I could mess around and do it myself but if someone here could write it out pretty quickly that would save me alot of time..
Re : Getting lowest number and storing it in a variable -
Mixcraft - 03.05.2012
I wondered about the same issue, solving this would be awesome !
Re: Getting lowest number and storing it in a variable -
MP2 - 03.05.2012
What variables do you want to order?
Re: Getting lowest number and storing it in a variable -
iTorran - 03.05.2012
Quote:
Originally Posted by MP2
What variables do you want to order?
|
Well I have this (new Fastest[8])
In those are times stored in MS.
What I need to do is get those MS and see which is lowest..
So that I can sort out the times in 1st, 2nd, 3rd, 4th, 5th, 6th, 7th and 8th.
Re: Getting lowest number and storing it in a variable -
MP2 - 03.05.2012
Will write when I get home. Not attempting on iPhone.
Apologies in advance for when I forget.
Re: Getting lowest number and storing it in a variable -
iTorran - 03.05.2012
Lol alright then
Re: Getting lowest number and storing it in a variable -
MP2 - 03.05.2012
Can't be bothered sorry, but here's my code for getting the closest player, it may be of some use:
pawn Code:
new Float:dist = FLOAT_INFINITY, closest_player = playerid;
new Float:pos[3], Float:this_dist;
foreach(new i : Player)
{
if(i == playerid) continue;
GetPlayerPos(i, pos[0], pos[1], pos[2]);
this_dist = GetPlayerDistanceFromPoint(playerid, pos[0], pos[1], pos[2]);
if(this_dist < dist)
{
closest_player = i;
dist = this_dist;
}
}
Re: Getting lowest number and storing it in a variable -
iTorran - 04.05.2012
Y_Less suggested that I sort the array..
But that wouldnt work, as I have also have another array with names..
So the names and times would need to be linked, while showing in order from fastest to slowest
Re: Getting lowest number and storing it in a variable -
Jefff - 05.05.2012
Show full example what You exactly want
Re: Getting lowest number and storing it in a variable -
iTorran - 05.05.2012
Quote:
Originally Posted by Y_Less
I don't see the problem there at all, why can't you link data and sort the array? YSI has a set of functions in y_bintree for exactly that.
|
Because I don't know how to do that efficiently :P