Program that finds the middle number

This is a discussion on Program that finds the middle number within the C++ Programming forums, part of the General Programming Boards category; this is a kind of nubish post, cause im still a noob, but dont you need braces or whatever they're ...

  1. #16
    Pokemon Master digdug4life's Avatar
    Join Date
    Jan 2005
    Location
    Mystic Island, NJ
    Posts
    91
    this is a kind of nubish post, cause im still a noob, but dont you need braces or whatever they're called for those if statements?
    Verbal Irony >>

    "I love english homework!" When really nobody like english homework.
    -Mrs. Jennifer Lenz (English Teacher)

  2. #17
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,077
    Quote Originally Posted by digdug4life
    this is a kind of nubish post, cause im still a noob, but dont you need braces or whatever they're called for those if statements?
    The only reason that is a noobish question is because I just answered it. I even gave multiple examples.

    Here it is... one more time.

    You don't need braces if the statement you wish to perform after the if statement is one line long. If it's more than one line, it needs braces.

    Code:
    if ( 1 == 1 )
       cout << "This is a proper if statement" << endl;
       cout << "...but this line isn't part of the if statement";
       
    if ( 1 == 1 ) {
       cout << "This is a proper if statement" << endl;
       cout << "Now this is part of the if statement";
    }
    
    if ( 1 == 1 )
       cout << "This " 
            << "is "
            << "also "
            << "all "
            << "part "
            << "of "
            << "the "
            << "if "
            << "statement." 
            << endl; // The semicolon ends the statement.
    Sent from my iPadŽ

  3. #18
    Registered User
    Join Date
    Sep 2005
    Posts
    25
    Thanks for the help again guys!

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program Plan
    By Programmer_P in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2009, 02:42 AM
  2. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 03:30 PM
  3. Random number + guessing game trouble
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-08-2007, 04:33 AM
  4. Fibonacci number program problem(assembly)
    By ok_good in forum Tech Board
    Replies: 7
    Last Post: 04-07-2006, 08:27 PM

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