Raised This Month: $51 Target: $400
 12% 

Finding out if a number is between two numbers


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Jordan
Veteran Member
Join Date: Aug 2005
Old 09-15-2006 , 19:17   Finding out if a number is between two numbers
Reply With Quote #1

If I wanted to find the value of x, would I just put

Code:
if(10 <= X <= 20) then do blah
?
Jordan is offline
P34nut
AMX Mod X Beta Tester
Join Date: Feb 2006
Location: Netherlands
Old 09-15-2006 , 19:20   Re: Finding out if a number is between two numbers
Reply With Quote #2

PHP Code:
if (yournum lownum && yournum highnum)
{
   
// yourcode

__________________
All you need to change the world is one good lie and a river of blood
P34nut is offline
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 09-15-2006 , 19:25   Re: Finding out if a number is between two numbers
Reply With Quote #3

satan, your way works.
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
MaximusBrood
Veteran Member
Join Date: Sep 2005
Location: The Netherlands
Old 09-15-2006 , 19:34   Re: Finding out if a number is between two numbers
Reply With Quote #4

It's called an inequality IIRC.

10 <= x <= 20
or
[10, 20]
__________________
Released six formerly private plugins. Not active here since ages.
MaximusBrood is offline
Jordan
Veteran Member
Join Date: Aug 2005
Old 09-15-2006 , 19:40   Re: Finding out if a number is between two numbers
Reply With Quote #5

ty ^_^
Jordan is offline
Zenith77
Veteran Member
Join Date: Aug 2005
Old 09-16-2006 , 12:38   Re: Finding out if a number is between two numbers
Reply With Quote #6

what


I don't think you can do this, if I am wrong about this, someone correct me.

Code:
if(10 <= X <= 20)

The '<=' or any other operator like that will essentially return 1 on true or 0 on false. Now, with that in mind, the first check will work fine, but since the first check

Code:
10 <= X

will always return 1 or zero, then the second check will always result in being true (1 and 0 are both less than or equal to 20), since this is basically read from left to right. So, you have a bug on your hands.

p34nut's code is correct.
__________________
Quote:
Originally Posted by phorelyph View Post
your retatred
Zenith77 is offline
MaximusBrood
Veteran Member
Join Date: Sep 2005
Location: The Netherlands
Old 09-16-2006 , 12:59   Re: Finding out if a number is between two numbers
Reply With Quote #7

Quote:
Originally Posted by Zenith77 View Post

[explaination]

p34nut's code is correct.
Yes, p34nut's code is correct, but you're explaination isn't.
Although it sounds plausible, boolean expressions output booleans, not 0 on false and 1 on true.

Just try it out yourself and see that it works.
Also, since inequalities are math functions, check this out:

http://en.wikipedia.org/wiki/Inequality (look at chained notation)
__________________
Released six formerly private plugins. Not active here since ages.
MaximusBrood is offline
VEN
Veteran Member
Join Date: Jan 2005
Old 09-16-2006 , 14:09   Re: Finding out if a number is between two numbers
Reply With Quote #8

Quote:
Originally Posted by Pawn Guide
Note: the following operators may be "chained", as in the expression "e1 <= e2 <= e3", with the semantics that the result is "1" if all individual comparisons hold and "0" otherwise.
(the following operators is a <, <=, >, >=)
VEN is offline
Jordan
Veteran Member
Join Date: Aug 2005
Old 09-16-2006 , 19:55   Re: Finding out if a number is between two numbers
Reply With Quote #9

So VEN my way should work bug free, right?
Jordan is offline
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 09-17-2006 , 01:04   Re: Finding out if a number is between two numbers
Reply With Quote #10

Quote:
Originally Posted by ^_^Satan^_^ View Post
So VEN my way should work bug free, right?
like i said before yes, i use it quite a lot
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:14.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode