Thread: Wrong answer?

  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    3

    Question Wrong answer?

    i am a noob at C++

    i was doing this quiz

    Cprogramming.com - Tutorials - C++ Programming Quiz - Loops

    the first answer should be B.9, shouldn't it?? i executed this ..after inserting cout<<x<<endl;

    and the last value was 9...how come the answer is 10?

    thanks

  2. #2
    Webhead Spidey's Avatar
    Join Date
    Jul 2009
    Posts
    285
    Note: This quiz question probably generates more email to the webmaster than any other single item on the site. Yes, the answer really is 10. If you don't understand why, think about it this way: what condition has to be true for the loop to stop running?

  3. #3
    Registered User
    Join Date
    Jun 2009
    Location
    Adeliade, AU
    Posts
    128
    It will be 10 as the final result.

    9 is smaller than 10 there fore it will be increased by 1 (x++)

    Now x = 10 therefore the loop will break

  4. #4
    Registered User
    Join Date
    Jul 2009
    Posts
    3
    Quote Originally Posted by Spidey View Post
    Note: This quiz question probably generates more email to the webmaster than any other single item on the site. Yes, the answer really is 10. If you don't understand why, think about it this way: what condition has to be true for the loop to stop running?
    lol...atleast i bothered to ask at the forum where many free people can answer me :P

    hmm...didnt think of it like that before. x would have to be = 10 finally i guess

    thanks

  5. #5
    Webhead Spidey's Avatar
    Join Date
    Jul 2009
    Posts
    285
    lol...atleast i bothered to ask at the forum where many free people can answer me :P
    What makes you think these 'people' are free ?
    If you always rely on others to answer your questions, you will never learn.
    Try giving it a thought first.

  6. #6
    Registered User
    Join Date
    Jul 2009
    Posts
    3
    Quote Originally Posted by Spidey View Post
    What makes you think these 'people' are free ?
    If you always rely on others to answer your questions, you will never learn.
    Try giving it a thought first.
    well...if you weren't free enough to answer the question..how did u?
    and i meant, more free than the webmaster
    and i did give a thought but i didnt understand the question properly

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question 26 Answer seems wrong on site quiz
    By Kleid-0 in forum C++ Programming
    Replies: 2
    Last Post: 04-16-2005, 03:03 PM
  2. whats wrong with this? no errors but wrong result
    By InvariantLoop in forum C Programming
    Replies: 6
    Last Post: 01-28-2005, 12:48 AM
  3. Replies: 9
    Last Post: 07-15-2004, 03:30 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM
  5. Half life Problem which I am right and the teacher is wrong
    By Shadow12345 in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 11-06-2002, 04:28 PM

Tags for this Thread