New to C What Is wrong with this...

This is a discussion on New to C What Is wrong with this... within the C++ Programming forums, part of the General Programming Boards category; Whitespace is not significant to the compiler. Just because all those lines after EditMenu==1 are indented, doesn't mean they are ...

  1. #16
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Whitespace is not significant to the compiler. Just because all those lines after EditMenu==1 are indented, doesn't mean they are actually part of the if-statement, so std::cin >> AddItem will always happen. (You only get one statement in an if, although you can make it a block if you want.)

  2. #17
    Registered User
    Join Date
    Aug 2009
    Posts
    31
    If I make it into a block does it solve the problem? Or is there a way so if I select option 1 to run only if statements in a block?

  3. #18
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    Quote Originally Posted by headshot119 View Post
    If I make it into a block does it solve the problem? Or is there a way so if I select option 1 to run only if statements in a block?
    That is what you need to do.

    Code:
    if(something)
        statement_1;
        statement_2;
        statement_3;
    In the above code, statement_1 is run if the if statement is true, but statements 2 and 3 are always executed. If you want all 3 statements only only get executed when the if statement is true, then do:
    Code:
    if(something)
    {
        statement_1;
        statement_2;
        statement_3;
    }
    bit∙hub [bit-huhb] n. A source and destination for information.

  4. #19
    Registered User
    Join Date
    Aug 2009
    Posts
    31
    Makes sense thanks Bithub

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

Similar Threads

  1. Replies: 9
    Last Post: 07-15-2004, 03:30 PM
  2. Debugging-Looking in the wrong places
    By JaWiB in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-03-2003, 09:50 PM
  3. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 12:40 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 11:01 AM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 01:04 PM

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