IF Statement not working

I'm having problems getting my if statements to work properly, I believe the syntax is correct but the output is not what I expected. This is the code:

#include

int main()

{
int num1;
int num2;

printf( "Relations between two numbers.
" );
printf( "Please, enter the numbers: " );

scanf( "%d%d", &num1, &num2 );

if ( num1 == num2 );
{
printf( "%d is equal than %d
", num1, num2 );
}

if ( num1 != num2 );
{
printf( "%d is different than %d
", num1, num2 );
}

if ( num1 < num2 );
{
printf( "%d is less than %d
", num1, num2 );
}

if ( num1 > num2 );
{
printf( "%d is greater than %d
", num1, num2 );
}

if ( num1 <= num2 );
{
printf( "%d is less or equal than %d
", num1, num2 );
}

if ( num1 >= num2 );
{
printf( "%d is greater or equal than %d
", num1, num2 );
}

return 0;
}

And this is the output, which is obviously wrong:

Relations between two numbers.
Please, enter the numbers: 25 44
25 is equal than 44
25 is different than 44
25 is less than 44
25 is greater than 44
25 is less or equal than 44
25 is greater or equal than 44


What am I doing wrong? Any help would be greatly appreciated. Thanks in advance!!

Edit: Code written using VIM and compiled with GCC under Ubuntu OS. Moved to my Win 7 comp and tried the same program using Dev-CC, worked perfectly there. Why?

Comments

  • have a try this code

    #include
    int main()
    {
    int num1,num2;
    /*Relations between two numbers.
    Please, enter the numbers: 25 44
    25 is equal than 44
    25 is different than 44
    25 is less than 44
    25 is greater than 44
    25 is less or equal than 44
    25 is greater or equal than 44*/

    printf("Enter two integers to check.
    ");
    scanf("%d %d",&num1,&num2);

    if(num1 == num2)
    printf("%d is equal to %d",num1,num2);
    if(num1 != num2)
    printf("%d is not equal to %d
    ",num1,num2);
    if(num1 < num2)
    printf("%d is less than to %d
    ",num1,num2);
    if(num1 > num2)
    printf("%d is greater than to %d
    ",num1,num2);
    if(num1 <= num2)
    printf("%d less than or equal to %d
    ",num1,num2);
    if(num1 >= num2)
    printf("%d is not equal to %d
    ",num1,num2);
    else
    printf("enk enk");


    return 0;
    }
  • Dont practice to put semi-colon(;) after the condition of the If statement. Someday or later it will give you an error.

    And the way you coded your if statement is wrong.. it was just actually printing the printf in the execution code. Whenever you input the numbers.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion