
-----------------------------------
unknowngiver
Thu Mar 09, 2006 11:05 am

odd even
-----------------------------------
hey
how do i find out if the user inputs an odd number or even
i want it to give an error if the number is EVEN

-----------------------------------
Delos
Thu Mar 09, 2006 11:33 am


-----------------------------------
Hello and welcome.

There is a Search Button up at the top there.  This particular question has been asked dozens of times in the past.  Additionally, it will help us to help you if you post a sample of the code you're currently working on and having difficulties with.
Unless you have a purely theoretical question, then try to include some code (make sure to use [code] tags when posting, or to attach it).  This ensures that we're not just throwing out answers but that the people asking are actually doing some work and just need some direction and guidance.

So, post up your own attempts at solving this and we'll see what we can do.  As a hint, you'll be using some nifty maths that involves finding remainders.

-----------------------------------
MysticVegeta
Thu Mar 09, 2006 2:37 pm


-----------------------------------
Check out the modulus (mod) function, it acts as a remainder function, rest help will be given by whatyou are learned in math  :wink:

-----------------------------------
Dan
Thu Mar 09, 2006 5:47 pm


-----------------------------------
And of corse if the remainder is 0 it is even and if it is not= 0 it is odd.

This should be prity easy to figgure out with the above, but if you need more help post what you got code wise.

-----------------------------------
unknowngiver
Thu Mar 09, 2006 11:34 pm


-----------------------------------
okie well i did try to search but i wasnt sucessfull
Basically here is the code

var ans :int
put "Please enter an odd number"
get ans

but now i want to check that if they are inputting an odd number or even number

Dan: i was kinda going that way
i know that i need some sort of a equation to do it
maybe

if ans=>2 then
put "its even"
else 
put "its odd"
end if


-----------------------------------
Dan
Fri Mar 10, 2006 12:03 am


-----------------------------------
Check out the modulus (mod) function, it acts as a remainder function, rest help will be given by whatyou are learned in math  :wink:

Try reading what others post. This function will give you the remainder, it is the remainder you most check to see if it is 0 or above.

I mean; obvesly not all numbers > 2 are even.

-----------------------------------
md
Fri Mar 10, 2006 12:06 am


-----------------------------------
If you divide an even number by two what is hte remainder?
If you divide an odd number by two what is the remainder?

Now... mod returns the remainder of one number divided by another... so

X mod 2 = ? when odd?
x mod 2 = ? when even?

Methinks you can work it out from there.
