0

I'm trying to make a 2D array that looks like:

----
----
----
----

For the life of my I can't figure it, I'm new to C++. Here are my attempts so far:

    char board[boardSize][boardSize];
    for(int i=0;i<boardSize;i++){
        for(int j=0;j<boardSize;j++){
            board[i][j]='-';
        }
    }
    for(int i=0;i<boardSize;i++){
        for(int j=0;j<boardSize;j++){
            cout<<board[i][j];
        }
    }

This gives:

----------------

Can anyone please direct me in the right direction? Thank you!

1 Answer 1

1
for(int i=0;i<boardSize;i++){
    for(int j=0;j<boardSize;j++){
        cout<<board[i][j];
    }
}

should be

for(int i=0;i<boardSize;i++){
    for(int j=0;j<boardSize;j++){
        cout<<board[i][j];
    }
    cout<<endl;
}

you're printing all the "lines" on one line.

Sign up to request clarification or add additional context in comments.

1 Comment

That worked! Thanks! I should have seen such an easy mistake.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.