Menu

Why this IF ELSE don't work? DEV-C ++

uoo
2009-09-27
2012-09-26
  • uoo

    uoo - 2009-09-27

    I am new at this and can't figure out why this don't work.... please help me.


    include <stdlib.h>

    include <stdio.h>

    int main()
    {
    float x;

    printf("Please enter your age\n");
    scanf("%d", &x);

    if( (x>=18) && (x<=55) )
    {
    printf("Transaction Accepted\n");
    }
    else {
    printf("Transaction Rejected\n");
    }

    system("PAUSE");
    return 0;
    }


     
  • cpns

    cpns - 2009-09-29

    Not very helpful! In what manner does it "not work"?

    The most obvious thing is that x is a float but you told scanf to expect an
    int - %d. Why float in any case? Who in the world other than Adrian Mole is
    going to enter 13.75 when asked for age?

    The compiler options -Wall -Wformat -Werror would have allowed the compiler to
    trap this error for you.

    Even though SourceForge's implementation is broken, you should apply the new
    code mark-up to code when posting.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.