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

I guess number is an integer, what are `odd` and `even` in your code?

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`

I suggest using a bitwise AND to test if the rightmost bit is a 0 or 1.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.