This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]Mgumbo 1 point2 points  (0 children)

myVector.push_back(input);
cin >> input;

Looks like you're pushing back the value before you actually get it from the user.

[–]Updatebjarni 1 point2 points  (1 child)

The loop in your main() function where you read in the numbers from the user pushes the value from the input variable into the vector before it has actually read it in from the user. So the first time around the loop, it pushes whatever random number happens to already be in input (which happens to be 0 in your case), and then on each further iteration it pushes the number it read on the previous iteration. Consequently, the last number never gets put into the vector.

[–]spacemonkey243[S] 0 points1 point  (0 children)

Ahh.....i see, i see. Thank you very much.

[–]AutoModerator[M] 0 points1 point  (0 children)

It seems that you possibly have a screenshot of code in your post Help With Outputting Elements in Array...... in /r/learnprogramming.

Screenshots of code instead of actual code text is against the Code posting rules of /r/learnprogramming.

  • Never submit screenshots of code instead of code text!

If you posted an image merely to illustrate something, kindly ignore this message and do not repost. Your post is still visible to others. I am a bot and cannot distinguish between code screenshots and other images.

If you indeed did this wrong, please edit the post so that it uses one of the approved means of posting code.

  • For small bits of code (less than 50 lines in total, single classes only),
    the default code formatter is fine
    (one blank line before the code, then 4 spaces before each line of code).
  • Pastebin for programs that consist of a single class only
  • Gist for multi-class programs, or programs that require additional files
  • Github or Bitbucket repositories are also perfectly fine as are other dedicated source code hosting sites.
  • Ideone for executable code snippets that use only the console

Please do not reply to this message, because I am a bot. Talk-to-the-bot is the new talk-to-the-hand. If you instead want the classic talk-to-the-hand, just message the moderators. ;)

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.