Question about array code

This is a discussion on Question about array code within the C++ Programming forums, part of the General Programming Boards category; So, I'm just starting to learn C++ and I'd like to start off by saying thank you to all those ...

  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
    2,904
    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, 11: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, 09:58 PM
  4. Replies: 4
    Last Post: 06-14-2005, 06:45 AM
  5. More Array code problems
    By Masa in forum C++ Programming
    Replies: 1
    Last Post: 04-08-2004, 03:04 AM

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