Why is my 'if' loop body not being processed?

#include <iostream>

int main()
{
    int a = 0, b = 0;
    std::cin >> a >> b;
    if ((a >> 9) || (b >> 9))
    {
        if (a >> 9)
        {
            for (int n = 9; n <= a; ++n)
            {
                if (n % 2 == 0)
                {
                    std::cout << n << "is even";
                }
                else
                {
                    std::cout << n << "is odd";
                }
            }
        }
        if (b >> 9)
        {
            for (int n = 9; n <= b; ++n)
            {
                if (n % 2 == 0)
                {
                    std::cout << n << "is even";
                }
                else
                {
                    std::cout << n << "is odd";
                }
            }
        }
    }
    return 0;
}

It is a program to print the numbers greater than 9 as even or odd from 10 till the numbers as input are achieved by increment. The program processing starts but the if loop is totally left, doesn't compile the body of if loop, kindly suggest what is the solution for this.

1 answer

  • answered 2018-10-11 19:06 Maddy

    you are doing bit shift operation instead of comparison, instead you should be doing something like below

    if (a > 9 || b > 9)