C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 07-16-2009, 05:30 AM   #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
eViLrAcEr is offline   Reply With Quote
Old 07-16-2009, 05:36 AM   #2
Webhead
 
Spidey's Avatar
 
Join Date: Jul 2009
Posts: 278
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?
Spidey is offline   Reply With Quote
Old 07-16-2009, 05:38 AM   #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
Aliaks is offline   Reply With Quote
Old 07-16-2009, 05:48 AM   #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
eViLrAcEr is offline   Reply With Quote
Old 07-16-2009, 05:56 AM   #5
Webhead
 
Spidey's Avatar
 
Join Date: Jul 2009
Posts: 278
Quote:
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.
Spidey is offline   Reply With Quote
Old 07-16-2009, 06:04 AM   #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
eViLrAcEr is offline   Reply With Quote
Reply

Tags
noob, tutorial

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Question 26 Answer seems wrong on site quiz Kleid-0 C++ Programming 2 04-16-2005 03:03 PM
whats wrong with this? no errors but wrong result InvariantLoop C Programming 6 01-28-2005 12:48 AM
Problem with input choice... Somethings wrong... really wrong.... greenferoz C++ Programming 9 07-15-2004 03:30 PM
God datainjector A Brief History of Cprogramming.com 746 12-22-2002 12:01 PM
Half life Problem which I am right and the teacher is wrong Shadow12345 A Brief History of Cprogramming.com 13 11-06-2002 04:28 PM


All times are GMT -6. The time now is 07:22 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

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