Author Topic: Wrong result in Codeblocks  (Read 5203 times)

Offline acer

  • Single posting newcomer
  • *
  • Posts: 2
Wrong result in Codeblocks
« on: June 10, 2020, 01:14:59 pm »
I am learning C++.I typed this code in a codeblocks project and when I run it , it gives me wrong result. I thought the error was with the code but I copied and pasted the same code in an online compiler and I got a different result. Here's the code

Code
#include <iostream>
#include  <math.h>

using namespace std;



int main()
{
    int age;
    cout <<"Enter your age ";
    cin >> age;
    if(age<12 || age>50)
    {
        cout<<"Eligible";
    }
    else
    {
        cout <<"Not Eligible";
    }


    return 0;
}

When compiling and running it with codeblocks if I  input the number 35 , I still get "Eligible". Any number I type, I get the result as "Eligible"  . In the tutorial video I got this code from, the instructor also uses Codeblocks but he gets the correct result . But I always  get the result as "Eligible" , even if I type a number bigger than 12 and lower than 50.

Offline acer

  • Single posting newcomer
  • *
  • Posts: 2
Re: Wrong result in Codeblocks
« Reply #1 on: June 10, 2020, 01:26:28 pm »
NVM. I changed the compiler in codeblocks and got the correct result.Solved.