Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 odd even
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
unknowngiver




PostPosted: Thu Mar 09, 2006 11:05 am   Post subject: 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
Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Thu Mar 09, 2006 11:33 am   Post subject: (No subject)

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




PostPosted: Thu Mar 09, 2006 2:37 pm   Post subject: (No subject)

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




PostPosted: Thu Mar 09, 2006 5:47 pm   Post subject: (No subject)

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.
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
unknowngiver




PostPosted: Thu Mar 09, 2006 11:34 pm   Post subject: (No subject)

okie well i did try to search but i wasnt sucessfull
Basically here is the code
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
code:

if ans=>2 then
put "its even"
else
put "its odd"
end if
Dan




PostPosted: Fri Mar 10, 2006 12:03 am   Post subject: (No subject)

MysticVegeta wrote:
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.
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
md




PostPosted: Fri Mar 10, 2006 12:06 am   Post subject: (No subject)

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.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: