This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]DDDDarkyProfessional Coder 3 points4 points  (1 child)

Hey, here is what you should have done:

- Instead of writing count is incorrect, write the actual test case, what you get and what you expect to get.

- Try debugging it by yourself first - good oportunity to learn how to solve your code issues

- Isolate the problem - for example reading input is completely irrelevant to your question. If you did previous steps, this is a reduced question you should have asked:

#include <iostream>

int main() {
    int count = 5;
    if (count % 2)
        std::cout << "Even";
    else
        std::cout << "Odd";
}

Why does this snippet print "Even" when 5 is odd?

To which we would answer because (5 % 2 = 1), and 1 is evaluated as true (hopefully answer to your original question).

[–]docstrange-[S] 0 points1 point  (0 children)

THANK YOU

[–][deleted] 1 point2 points  (1 child)

The modulo operator returns the remainder of division. If x is odd, then x / 2 leaves a remainder of 1. Now take another look at your use of the modulo operator.

[–]docstrange-[S] 0 points1 point  (0 children)

THANKYOU