Thread: Question about array code

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    4

    Question about array code

    So, I'm just starting to learn C++ and I'd like to start off by saying thank you to all those that created this site. It's been great and the guides are very helpful.

    During the course of trying out example code for arrays, I ran into an issue where the code doesn't terminate when expected. In fact, it just goes until my computer gives an error response. So my question is: given the code below, which is a copy of what I have entered and is almost a copy/paste from the example, why doesn't it terminate on its own?

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        int x;
        int y;
        int array[8][8];
    
        for ( x = 0; x < 8; x++ ) {
            for ( y = 0; y < 8; y++ )
                array[x][y]= x * y;
        }
        cout<<"Array Indices:\n";
        for ( x = 0; x < 8; x++ ) {
            for ( y = 0; x < 8; y++ )
                cout<<"["<<x<<"]["<<y<<"]="<< array[x][y] <<" ";
            cout<<"\n";
        }
        cin.get();
    }
    Thanks in advance. I know this is probably really basic stuff, but I only started yesterday.

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    In your print out loops check this line out :
    Code:
           for ( y = 0; x < 8; y++ )
    Does it seem correct?

    Jim

  3. #3
    Registered User
    Join Date
    Apr 2011
    Posts
    4
    Wow, thanks for the spot! I feel kind of dumb, but clearly I need to read over my stuff a bit more carefully.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 04-07-2010, 10:03 PM
  2. beginner here need help with an array code
    By Ohshtdude in forum C++ Programming
    Replies: 6
    Last Post: 02-01-2009, 05:42 PM
  3. Noob question! Code completion - Array challenge
    By theleprechaun in forum C++ Programming
    Replies: 6
    Last Post: 08-22-2008, 08:58 PM
  4. Replies: 4
    Last Post: 06-14-2005, 05:45 AM
  5. More Array code problems
    By Masa in forum C++ Programming
    Replies: 1
    Last Post: 04-08-2004, 02:04 AM