### Odds and Evens

I am trying to figure out a way to ask for two numbers (num1 and num2) and then output all the even numbers then all of the odd numbers. I know that the evens are divisible by two but i just cant seem to get the wording right in my head to write it out.....
The modulous operator (%) tells you the remainder of integer division:

sudo code:
IF (x % 2 is 1)
THEN x is Odd
ELSE x is Even
Last edited on
This will work if i am just trying to find out if x is odd or even, but I have to have two numbers and get all the evens and odds in between those two numbers
Loop through the values:
 ``12345`` ``````for(int i=firstvalue;i<=secondvalue;i++) if((i % 2) == 1) //... else //... ``````
Last edited on
Just loop over all numbers between the two input ones, and output the evens.

Then loop over all numbers between the two input ones again, and output the odds.
How would you use this in a while loop then
You are being lazy. This is not only information you should already have been given in school, in your textbook, and on the web (including a very complete section on loops on this very site), you have also already been given an example of a loop in this very thread.

I won't do your homework or your thinking for you.
Cool story bro...tell it again..........

I'm not asking anyone to do any homework for me. I am trying to learn this on my own and the book that I have bought sucks. If you want to help, awesome, if not then leave the lectures at the door and don't comment. If someone could reference me to the looping section that super dad above was talking about I would be eternally grateful....Thanks
Bull. You don't just want knowledge. You are asking to be spoonfed. This is actually one of the most forgiving and friendly sites you will find on the internet and I'm not lecturing to say FIND IT YOURSELF. Your eternal gratitude means nothing.

Learning to gather information is vital to computer programming.

I am always amazed at the small but significant percentage of people who will post here asking for help and then get angry when they dislike all the (in this case, very good) answers they are given.

Just so you can't justly complain any more:
-
Google around "c/c++ for loop"
-
Next stop, click the big "cplusplus.com" logo in the upper left of your browser window and follow the link for "C++ Language Tutorial". There is a whole section there on "control structures".

If you are still lost then take your smug hippie better-than-you crap elsewhere and see how far you get. My sugar basket for you is empty.