Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Dec 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy where is the problem??

    very simple code but the problem is, if condition not working. though i put "first condition=1.1" it skips if condition and print only else...please help me


    #include<stdio.h>
    main()
    {
    int i;
    float con;
    printf("first condition:");
    scanf("%f",&con);
    if(con==1.1)
    {

    for(i=0;i<10;i++)
    printf("%d\n",i);
    }
    else
    printf("nothing");
    }

  • #2
    New Coder
    Join Date
    Jan 2011
    Posts
    76
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Did you try wrapping your value?

    Code:
    if(con="1.1")

  • #3
    New to the CF scene
    Join Date
    Dec 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    no its not working...cant write the condition like this...its not the rule.

  • #4
    New Coder
    Join Date
    Jan 2011
    Posts
    76
    Thanks
    8
    Thanked 0 Times in 0 Posts
    im sorry i couldn't help you but i cant imagine that 1.1 is not causing problems, I don't even know what language this is but the period does not seem right to me without being wrapped in something eg " " or ' ' . Have you tried with just 1 or 11 to debug?

    define your var con=1

    then if con==1

  • #5
    Regular Coder Nerevarine's Avatar
    Join Date
    Jan 2013
    Location
    Phendrana Drifts, Tallon IV, W-Class
    Posts
    285
    Thanks
    0
    Thanked 17 Times in 17 Posts
    Blog Entries
    3
    You have two execution statements.

    The 'if' is a conditional statement and the 'for' is a conditional statement.

    Your else is being executed because you have no 'then'. The syntax has to be 'if, then, else'.
    Time kills us in our sleep and we watch it happen in our dreams. -K.K.
    THE END-ALL PROGRAMMING REFERENCE: CLICK HERE (Courtesy of Major Payne)
    My username was previously L0adOpt1c. :: Please read this before posting in the HTML/CSS forum.
    Validate your HTML here and your CSS here. :: Need basic HTML/CSS tutorials? Click here, don't post about it.

  • #6
    New to the CF scene
    Join Date
    Dec 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    #include<stdio.h>
    main()
    {
    int i;
    float con,x=1.1;
    printf("first condition:");
    scanf("%f",&con);
    if(con==x)
    {

    for(i=0;i<10;i++)
    printf("%d\n",i);
    }
    else
    printf("nothing");
    }

    its work @embeebutterly its C programming...nd thnx everyone for ur concern

  • #7
    Regular Coder Nerevarine's Avatar
    Join Date
    Jan 2013
    Location
    Phendrana Drifts, Tallon IV, W-Class
    Posts
    285
    Thanks
    0
    Thanked 17 Times in 17 Posts
    Blog Entries
    3
    Let us know if you need any more help.
    Time kills us in our sleep and we watch it happen in our dreams. -K.K.
    THE END-ALL PROGRAMMING REFERENCE: CLICK HERE (Courtesy of Major Payne)
    My username was previously L0adOpt1c. :: Please read this before posting in the HTML/CSS forum.
    Validate your HTML here and your CSS here. :: Need basic HTML/CSS tutorials? Click here, don't post about it.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •