0

I’m new to this and talking an intro class. I’ve read and reread my course material so far and I can’t get this line to work.
It has to display You have 2 even and 3 odd numbers but no matter what I do, it keeps coming out with 0 even and 0 odd.
Tried used if (number %2==0){ number = even}
If(number %2!=0){ number = odd} but that’s not working. Any suggestions

4
Contributors
4
Replies
52
Views
2 Months
Discussion Span
Last Post by Smith5646
0

Oh, I guess I see now. I think odd stands for the number of odds and even for the number of evens. Right?
Instaed of using number = even, use even++ or even = even +1

0

Just to clarify where your error is...

if you find an even number, you are executing a boolean statement (number = even).
if you find an odd number, you are executing a boolean statement (number = odd).

You are never incrementing even or odd. That is what ddanbe is showing you with even++ or even = even +1.

if (number %2==0)
{
    even++;
}
else
{
    odd++;
}

And, to Reverand Jim's point, the bitwise function is more efficient than the mod function but since you are "new to this" you probably haven't stumbed over bitwise functions.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.