Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Stupid question: Function to determine higer,medium,and lower of 3 different numbers

Author
Message
ZioNz
21
Years of Service
User Offline
Joined: 4th Sep 2003
Location:
Posted: 7th Jun 2004 21:18
Hi i need to order 3 numbers from higher to lower. Im need something like:
a=1
b=5
c=3

first=higer(a,b,c)
second=medium(a,b,c)
last=lower(a,b,c)

I tryed using LOTS of IF commands, but it's a little confusing.

pd: Sorry for my bad english.

-
OSX Using Happy Dude
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 7th Jun 2004 21:49
You could either sort the numbers and then use the first array index as perhaps the lowest, the last as the highest etc
Or use some min and max functions (availiable from my plug-ins).

It would so something like :

lowest=min(a,b):lowest=min(lowest,c)
highest=max(a,b):highest=max(highest,c)

Dont have anything for finding the middle values though.


The place for wonderful plug-ins and things.
Keep your friends close, and your cats even closer.
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 7th Jun 2004 22:16 Edited at: 8th Jun 2004 22:55
function higher(a,b,c)
if a>b and a>c
value=a
endif
if b>a and b>c
value=b
endif
if c>a and c>b
value=c
endif
endfunction value

function middle(a,b,c)
if (a>b and a<c) or (a<b and a>c)
value=a
endif
if (b>a and b<c) or (b<a and b>c)
value=b
endif
if (c>a and c<b) or (c<a and c>b)
value=c
endif
endfunction value

function lower(a,b,c)
if (c<a) and (c<b)
value=c
endif
if (b<a) and (b<c)
value=b
endif
if (a<b) and (a<c)
value=a
endif
endfunction value

that should work, it looks a little long winded but actualy its`s shorter than trying to make a universal function that can return each of the values one by one according to a flag value or something, if you had more than three values to compare then you would find it worth the while to make something more elegant, but this simple method is easier for just comparing three values.

Mentor.

PC1: P4 hyperthreading 3ghz, 1gig mem, 2x160gig hd`s, Nvidia FX5900 gfx, 6 way surround sound, PC2: AMD 1.2ghz, 512mb ram, FX5200 ultra gfx, stereo 16 bit soundblaster, ups.
Rob K
Retired Moderator
22
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 8th Jun 2004 00:22 Edited at: 8th Jun 2004 00:23


BlueGUI:Windows UI Plugin - All the power of the windows interface in your DBPro games. - Plus URL download, win dialogs.
Over 140 new commands
ZioNz
21
Years of Service
User Offline
Joined: 4th Sep 2003
Location:
Posted: 8th Jun 2004 00:45
Hi,both Mentor and Rob K codes worked good ( i had to add a little endif on mentor's higher function) , thanks you all for the reply.

-
OSX Using Happy Dude
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 8th Jun 2004 01:21
What ? You didn't use my plug-in ? I'm all upset now...


The place for wonderful plug-ins and things.
Keep your friends close, and your cats even closer.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 8th Jun 2004 02:18
Here's my version using my array plug-in, and it'll work for any number of items in the array



*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins, source and the Interface library for Visual C++ 6, .NET and now for Dev-C++ http://www.matrix1.demon.co.uk
Fallout
22
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 8th Jun 2004 02:52
You guys and your plugins!!!! You remind me of the car salesman I'll be seeing tomorrow.

Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 8th Jun 2004 03:01
run the numbers through a sort function

"eureka" - Archimedes

Login to post a reply

Server time is: 2025-05-27 20:50:27
Your offset time is: 2025-05-27 20:50:27