what is wrong with my if statement

This is a discussion on what is wrong with my if statement within the C Programming forums, part of the General Programming Boards category; 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); ...

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,471
    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 */
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,422
    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, 04: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, 11:01 AM
  5. Something wrong with this if statement?
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 04-30-2002, 05:19 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21