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 Discussion / Even / Odd

Author
Message
Mattman
21
Years of Service
User Offline
Joined: 5th Jun 2003
Location: East Lansing
Posted: 4th Dec 2004 14:08
How could i figuire out if a number is even or odd?

Song of the whenever i feel like updating it....
Man in a Dress, by Stew
robo cat
21
Years of Service
User Offline
Joined: 23rd Feb 2004
Location: In a cat litter tray, near you...
Posted: 4th Dec 2004 17:21
`Heres a function for what you want:



The left hand side of the if statement will be an integer, the right hand side is a float (real number) so if they are equal then it is even.

Simple... yet fun!
Mattman
21
Years of Service
User Offline
Joined: 5th Jun 2003
Location: East Lansing
Posted: 5th Dec 2004 04:20
Thanks, this is exactly what I wanted!

Song of the whenever i feel like updating it....
Man in a Dress, by Stew
BearCDPOLD
21
Years of Service
User Offline
Joined: 16th Oct 2003
Location: AZ,USA
Posted: 5th Dec 2004 10:36
need........modulus......

Crazy Donut Productions, Current Project: Project Starbuks
Sony stole our name!
Mattman
21
Years of Service
User Offline
Joined: 5th Jun 2003
Location: East Lansing
Posted: 5th Dec 2004 11:17
...?

Song of the whenever i feel like updating it....
Man in a Dress, by Stew
comando 300
21
Years of Service
User Offline
Joined: 23rd Nov 2003
Location:
Posted: 5th Dec 2004 12:54
if variable=any odd number it will return 1.

I made another one




CURRENT PROJECT: RETRO PAC-MAN
Arkheii
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: QC, Philippines
Posted: 5th Dec 2004 18:53
@Mattman: Modulus is the remainder after division.



Of course, integers only. Funny, in vb6 if x is negative then it returns negative, regardless of y. In my pocketpc's 3rd party scientific calculator, if y instead is negative then the result is negative. So I went with vb6 because nobody's complained about its mod operator yet.


I spelled "disappointment" wrong. Pahintulutan ang di-inaasahang nakakahiyang pagkakamaling dulot ng kamangmangan. Have at you.
Emperor Baal
21
Years of Service
User Offline
Joined: 1st Dec 2003
Location: The Netherlands - Oudenbosch
Posted: 5th Dec 2004 19:52
why just not:

function even(x)
if x MOD 2 = 0 then exitfunction 1
endfunction 0

Arkheii
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: QC, Philippines
Posted: 6th Dec 2004 18:44
@Baal: Dunno. Ask them

There's a lot of fun stuff you can do with mod. I'm surprised it's not included in the DBC syntax.


I spelled "disappointment" wrong. Pahintulutan ang di-inaasahang nakakahiyang pagkakamaling dulot ng kamangmangan. Have at you.
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 6th Dec 2004 23:58
It's not included in DBP's syntax either, but it's there. I dont know if mod is in classic though.

"eureka" - Archimedes

Login to post a reply

Server time is: 2025-05-24 19:07:38
Your offset time is: 2025-05-24 19:07:38