mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jan 2004
Posts: 15
J
jONEz Offline OP
Pikka bird
OP Offline
Pikka bird
J
Joined: Jan 2004
Posts: 15
How can I test if a integer variable is odd or even? I know in C++ theres the modulos (sp?) command %, but mIRC didn't seem to like that as I'm not surprised, I checked the FAQ and Help file but cant seem to find a function to test for it, or some alternate syntax for the modulos (sp?) command, what do I need to do?

Thanks again!!

Last edited by jONEz; 21/02/04 03:28 PM.
Joined: Nov 2003
Posts: 2,327
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,327
Code:
alias even { return $iif(2 // $1,1,0) }

//echo -a $even(2) - returns 1
//echo -a $even(3) - returns 0

then you can use:
if $even(blah) { dostuff }



New username: hixxy
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
mIRC has the modulo operator, you simply have to use it within $calc() as with all arithmetic operators.
odd return $calc($1 % 2)

It seems to be a bit faster than the $even() example you've been given already.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
if (yournumber & 1) { echo im odd }
if (yournumber !& 1) { echo im even }


Link Copied to Clipboard