IF statements

This is a discussion on IF statements within the C++ Programming forums, part of the General Programming Boards category; Hi, first post here and a very big n00b at programming, im learning it for my A/AS-levels at school, so ...

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    7

    Post IF statements

    Hi, first post here and a very big n00b at programming, im learning it for my A/AS-levels at school, so [please go easy on me. I dont know a lot thats why im here.

    Basically, im sure theres obviously something VERY big im missing here, if staements, heres the code

    Code:
    #include <stdio.h>
    #include <cstdlib>
    
    int main()
    
    {
        
        int first;
        int second;
        int third;
        
        scanf("%d", &first);
        scanf("%d", &second);
        scanf("%d", &third);
        
        if((first > second) && (second > third));
                  printf("%d", first);
    
        if((first > third) && (second < third));
                  printf("%d", first);
    
    
    
        if((second > first) && (first > third));
                   printf("%d", second);
    
        if((second > third) && (first < third));
                   printf("%d", second);
    
    
    
        if((third > second) && (second > first));
                  printf("%d", third);
     
        if((third > first) && (second < first));
                  printf("%d", third);
        
        
    }
    All that happens is that it prints out everythign i have defined and entered, it prints out the 3 numbers twice, obviously because the printf's are not relating to the if staements at all, whats missing or there thats worng. Can you help??

    Thanks, dragon2309

  2. #2
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    You are right your printf statements are not relateted to the if's
    That's because of the semicolons after the if-statements.
    Remove them.
    Kurt

  3. #3
    Registered Loser nickodonnell's Avatar
    Join Date
    Sep 2005
    Location
    United States
    Posts
    33
    Edit: Nevermind, beat me to it.
    Last edited by nickodonnell; 10-01-2005 at 09:19 AM.

  4. #4
    Registered User
    Join Date
    Oct 2005
    Posts
    7
    ah dam, thanks kurt. Knew it would be something simple, just couldnt see it.

    thanks again, dragon2309

  5. #5
    Registered User byte's Avatar
    Join Date
    Aug 2005
    Posts
    8
    You don't have a return statement too.

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    7,338
    >> You don't have a return statement too.

    In C++, a return statement is not required. It is perfectly legal to leave it out. The main function is special in that it automatically returns 0 if you don't provide the return statement. (This assumes you have a standards-conforming compiler).

  7. #7
    Dae
    Dae is offline
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Quote Originally Posted by Daved
    >> You don't have a return statement too.

    In C++, a return statement is not required. It is perfectly legal to leave it out. The main function is special in that it automatically returns 0 if you don't provide the return statement. (This assumes you have a standards-conforming compiler).
    I was going to post that also, but saw that the OP is actually programming in C, and in C it is required.

    But now that I return to this post, I notice the OP has #include <cstdlib>.. So he is programming in C++, using C libraries. Whoever is teaching you should be fired..
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Unknown memory leak with linked lists...
    By RaDeuX in forum C Programming
    Replies: 6
    Last Post: 12-07-2008, 03:09 AM
  2. newbie question - if statements without conditions
    By c_h in forum C++ Programming
    Replies: 2
    Last Post: 07-18-2008, 10:42 AM
  3. C++ If Statements Help
    By moporho in forum C++ Programming
    Replies: 19
    Last Post: 01-18-2008, 07:40 AM
  4. Efficiency of case statements
    By Yasir_Malik in forum C Programming
    Replies: 26
    Last Post: 05-23-2006, 11:36 AM
  5. Need help with "if" statements
    By Harryt123 in forum C Programming
    Replies: 22
    Last Post: 05-14-2006, 08:18 AM

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