Thread: Simple Question

  1. #1
    Registered User
    Join Date
    Jan 2015
    Posts
    2

    Simple Question

    Assume all variable are declared correctly, the following for loop executes how many times?
    for (i = 0; i <= 20; i++)
    cout << I;

    I think 20 but am not sure.

  2. #2
    Tweaking master Aslaville's Avatar
    Join Date
    Sep 2012
    Location
    Rogueport
    Posts
    528
    Quote Originally Posted by fb3342 View Post
    Assume all variable are declared correctly, the following for loop executes how many times?
    for (i = 0; i <= 20; i++)
    cout << I;

    I think 20 but am not sure.
    You are right.

    [Edit]

    Am wrong
    Last edited by Aslaville; 01-27-2015 at 10:08 AM.

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    You are incorrect. How many numbers are there, between 0 and 20, inclusive? Remember that you're using <=, and not <.

    Also note that in your cout, you're trying to output a variable that has not been declared.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  4. #4
    Registered User
    Join Date
    Nov 2013
    Posts
    107
    Quote Originally Posted by Elkvis View Post
    You are incorrect. How many numbers are there, between 0 and 20, inclusive? Remember that you're using <=, and not <.

    Also note that in your cout, you're trying to output a variable that has not been declared.
    A bit patronising the way your put that, you could clearly see they meant i and not I.

  5. #5
    Lurker
    Join Date
    Dec 2004
    Posts
    296
    Quote Originally Posted by jim_0 View Post
    A bit patronising the way your put that, you could clearly see they meant i and not I.
    There was nothing patronizing about that at all.

    In fact, I think Elkvis should also told the OP to post code inside code tags and also pointed out that the OP should have made sure his/her code compiled before posting it.

    It is really disrespecting to come to a forum and not follow the forum guidelines when posting.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,998
    Quote Originally Posted by Jimmy
    I think Elkvis should also told the OP to post code inside code tags and also pointed out that the OP should have made sure his/her code compiled before posting it.
    It would have been even better if fb3342 had written a program to test his/her hypothesis of 20, then come here and ask why the result was 21, assuming he/she was unable to figure that out too.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    Jan 2015
    Posts
    2

    Sorry

    Quote Originally Posted by Jimmy View Post
    It is really disrespecting to come to a forum and not follow the forum guidelines when posting.
    First time poster. I should've read the guidelines first. I do feel, however, that your criticism was harsh and not at all constructive.

    Everyone else thanks for your help. Next time I will run a compilable code first.

  8. #8
    Lurker
    Join Date
    Dec 2004
    Posts
    296
    Quote Originally Posted by fb3342 View Post
    First time poster. I should've read the guidelines first. I do feel, however, that your criticism was harsh and not at all constructive.

    Everyone else thanks for your help. Next time I will run a compilable code first.
    My critique was actually not directed towards you. Everybody gets that wrong the first time here. My point was that Elkvis was not patronizing, he was just trying to be helpful.

    If you are about to start taking part of technical forums then How To Ask Questions The Smart Way and Short, Self Contained, Correct Example are two good reads which will help you get better help.

    I do think you where wrong in one thing. My critique might have been harsh, but it was also very constructive. Doing things right will get you help, doing it wrong will probably not in the long run. If you don't believe me, then you only have to look through the threads and see which post got help and which posts didn't.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. simple simple design question
    By Chaplin27 in forum C++ Programming
    Replies: 6
    Last Post: 05-31-2005, 11:33 PM
  2. a simple C question...
    By DramaKing in forum C Programming
    Replies: 10
    Last Post: 07-28-2002, 02:04 PM
  3. a simple question
    By ... in forum C++ Programming
    Replies: 1
    Last Post: 03-04-2002, 04:21 PM
  4. Simple question
    By Unregistered in forum Windows Programming
    Replies: 5
    Last Post: 02-10-2002, 09:34 PM
  5. A Simple Question
    By Unregistered in forum Windows Programming
    Replies: 1
    Last Post: 10-26-2001, 05:23 PM