Thread: help with code

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

    help with code


    While ( x <= 100 )
    total += x
    ++x;

    any idea what's wrong with this code? I am so lost

  2. #2
    ^ Read Backwards^
    Join Date
    Sep 2005
    Location
    Earth
    Posts
    282
    Code:
    while ( x <= 100 )
    {
    total += x;
    ++x; // Or x++, in this case it does not matter; but at times the difference can become huge
    }
    Please start using code tags!
    Besides the missing semi colon and the {} it worked. Was that your problem or are you not getting the results you expect?

  3. #3
    Unregistered User
    Join Date
    Sep 2005
    Location
    Antarctica
    Posts
    341
    one possibility (besides the fact that Enahs pointed out and that your while has a capitalized W) is that you didn't initialize x, so it's a value over 100 already.

    Code:
    int x = 0;
    while(x <= 100)
    ...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 08:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM