Thread: two-dimensional array question

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    16

    two-dimensional array question

    I'm starting to design a basic minesweep type program. The minefield is going to be a two-dimensional array. When it prints out, the field gets shifted over one space in the 10th row since 10 is obviously larger than 9. Any suggestions on how to make it even?


    Code:
    #include <iostream>
    #include <conio>
    using namespace std;
    
    
    void main()
    {
            int row, col, x;
            col=0;
            row=0;
            x=1;
    
            cout<<"         1 2 3 4 5 6 7 8 9 10";
            char minefield[10][10];
    
            for (row=0; row<10; row++)
            {
                    cout<<"\nRow "<<x<<":  ";
                    x=x++;
    
                    for (col=0; col<10; col++)
                    {
                            cout<<" -";
                    }
    
            }
    
    
            getch();
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > void main()
    It's int main - see the FAQ

    > x=x++;
    This is undefined - do one of
    x++;
    x = x + 1;
    x += 1;

    > cout<<"\nRow "<<x<<": ";
    Perhaps you also want to output the width of the field as well, as in
    cout<<"\nRow "<< setw(2) << x<<": ";

    I think you also need to
    #include <iomanip>
    as well

  3. #3
    Registered User
    Join Date
    Oct 2005
    Posts
    16
    Thank you very much!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Embaracing Array question
    By DavidDobson in forum C Programming
    Replies: 2
    Last Post: 04-06-2009, 10:29 AM
  2. Dynamic Mutli dimensional Array question.
    By fatdunky in forum C Programming
    Replies: 6
    Last Post: 02-22-2006, 07:07 PM
  3. two dimensional string array question
    By Hoser83 in forum C Programming
    Replies: 8
    Last Post: 02-07-2006, 08:15 PM
  4. Array of Structs question
    By WaterNut in forum C++ Programming
    Replies: 10
    Last Post: 07-02-2004, 02:58 PM
  5. Create Array size Question
    By popohoma in forum C++ Programming
    Replies: 3
    Last Post: 11-04-2002, 03:04 AM