News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

Wrong result in Codeblocks

Started by acer, June 10, 2020, 01:14:59 PM

Previous topic - Next topic

acer

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

#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.

acer

NVM. I changed the compiler in codeblocks and got the correct result.Solved.