Odd or even?

Hi everybody,

I am making a programme in which I have to check at some point wether a number is odd or even, and then based on the check do something. (In my case divide by 2 if even, and if odd multiply the number by 3 and add 1, then the number gets even again so the programme needs to divide by 2 again etc. until the programme reaches the number 1).

Could somebody help me please? I haven't been programming in C++ for about a year now so I've forgotten almost everything...

Thanks! =)
Consider counting in binary. Try to find some kind of pattern.
Well, you'll need an if-else block which I hope you remember how to do, if not:
http://cplusplus.com/doc/tutorial/control/

As for the condition of the if-else... do you remember the modulo (%) operator? It returns the remainder of a division, if you don't. The remainder of any division by two of an odd number will be 1, else 0.

Does that help?

-Albatross
Hey,

Yes, I do remember how an if-else block works =).

As for the modulo operator, thanks alot! I totally forgot that one ;)

Should work out now, thanks!

Greets
Topic archived. No new replies allowed.