Noob question! Code completion - Array challenge

This is a discussion on Noob question! Code completion - Array challenge within the C++ Programming forums, part of the General Programming Boards category; Hello. I've decided to teach myself C++. So for the past week or so I've been reading the tutorials on ...

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    3

    Noob question! Code completion - Array challenge

    Hello.
    I've decided to teach myself C++. So for the past week or so I've been reading the tutorials on this site, doing the examples etc. I finished the tutorials and decided to try the challenges. And I got stuck on the first!!!

    After trying unsuccessfully to get my program to work, I looked at Cprogramming.com's solution, compiled it, ran it, and even the solution doesn't work!

    When running it fills in the element of the array (I presume) but it does not list them(I take list to mean print) and instead just exits.

    So, is my compiler broken? Or is there some incredibly noobish mistake that i can't see(most likely)

    Below is the solution, as posted by Cprogramming.com:

    When completed, the following program should first fill in (by asking the user for
    input) and then list all the elements in an array:

    Code:
    #include <iostream>
          using namespace std;
          int main()
    {
      int array[8];
      for(int x=0; x<8; x++)
      cin>> array[x];
      for(int x=0; x<8; x++)
      cout<< array[x];
      return 0;
    
    }
    Hope I've clarified enough

  2. #2
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,181
    You need to type in 8 values first (followed by [enter]s). Would probably be clearer if there was a prompt.

  3. #3
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,650

  4. #4
    Registered User
    Join Date
    Aug 2008
    Posts
    3
    The program prompts me for array input, and allows me to type in the 8 numbers, but then it exits, without printing them.

    So I would guess the problem is in the second If statement

  5. #5
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,181
    The problem is not in the actual program. Read the FAQ entry.

  6. #6

    Join Date
    May 2005
    Posts
    1,041
    I have balls.

    Code:
    #include <iostream>
    #include <conio.h>
    
    using namespace std;
    int main()
    {
    	int array[8];
    	for(int x=0; x<8; x++)
    		cin>> array[x];
    	for(int x=0; x<8; x++)
    		cout<< array[x];
           getch();
    	return 0;
    }
    now leave me alone. Seriously.
    I'm not immature, I'm refined in the opposite direction.

  7. #7
    Registered User
    Join Date
    Aug 2008
    Posts
    3
    Ah, I see. Got it now, Thank you for the help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 11-24-2005, 12:30 AM
  2. 2d array question
    By JoshR in forum C++ Programming
    Replies: 5
    Last Post: 04-09-2005, 12:52 PM
  3. linked list inside array of structs- Syntax question
    By rasmith1955 in forum C Programming
    Replies: 14
    Last Post: 02-28-2005, 04:16 PM
  4. Array of Structs question
    By WaterNut in forum C++ Programming
    Replies: 10
    Last Post: 07-02-2004, 02:58 PM
  5. End of Code Loop Question
    By JuanSverige in forum C++ Programming
    Replies: 1
    Last Post: 04-08-2003, 10:35 AM

Tags for this Thread


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