First things first, welcome to the ranch.
I will try to answer your question to the best of my abilities. But I don't think you're asking quite what you think you want.
Pointdexter Huynh wrote:I honestly don't understand what to do with the while loop and how to find even and odd numbers.
I am confused. So you are effectively using the while loop here:
Then inside you're checking, using
modulo:
That statement in the if is the modulo. You are checking if a given value's remainder when divided by two, is 0 (since modulo or % gives you the remainder when divided by the number on the right).
So using mod you can check the remainder of a number. All even numbers by definition are divisible by 2, and all non even (i.e, odd) are not divisible by two.
However there are a couple problems with the code you posted. First you said you wanted:
Pointdexter Huynh wrote:
2. Output all the even numbers between firstNum and secondNum...
So your loop should go from firstNum to secondNum. But in your loop you're comparing to secondNum only.
You should instead consider comparing to firstNum (Because that is what the problem is asking exactly.
But we also see a problem occurring here. Lets look at some values "going into" the while loop, and consider what they will do:
The first thing you're missing is "changing firstNum".
You need something along these lines as the first step to solving this problem:
There are other problems. But once you get past this first one at least your program will run. (Well.. you may have to define sumE and sumO as 0 first)