Thread: what is wrong with my if statement

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    62

    what is wrong with my if statement

    can someone help me identify what is wrong with this
    Code:
    #include<stdio.h>
    #include<stdlib.h>
    #include<conio.h>
    
    main()
    {     float a;
          scanf("%f",a);
          if(0<49);
          {
                   printf("you got D");
          }
          else if(50>60);
          {
               printf("you got c");
             }
          else 
          {
               printf("you have A");
               }
         getch(); 
          }

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    0 is always less than 49

    you want to check if a is in the interval [0,49) - you need to include a in the statement...

    like
    Code:
    if(a>=0 && a < 49)
    also scanf needs pointer to a to be able change its value
    Code:
    if(scanf("&#37;f", &a) == 1)
    {
       /* scanf succesful */
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    83

    why Semilcolons at end of...

    Those semicolons giving errors in VC++

    Code:
          if(0<49);
          {
                   printf("you got D");
          }
          else if(50>60);
          {
               printf("you got c");
             }
    error C2181: illegal else without matching if
    error C2181: illegal else without matching if

  4. #4
    Registered User
    Join Date
    Feb 2008
    Posts
    62
    oh thank i totally forgot

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Don't out semicolon after if statements.
    Also see http://cpwiki.sourceforge.net/Implicit_main
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what is wrong with my if statement
    By joker_tony in forum C Programming
    Replies: 6
    Last Post: 05-10-2008, 02:11 AM
  2. switch case statement
    By stanlvw in forum C++ Programming
    Replies: 3
    Last Post: 02-26-2008, 05:06 AM
  3. What's wrong with my success statement??
    By cool_dude07 in forum C Programming
    Replies: 7
    Last Post: 07-21-2007, 11:22 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM
  5. Something wrong with this if statement?
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 04-30-2002, 05:19 PM