Multidimensional Character Arrays Help!!!

I'm trying to create Minesweeper and I need help with 2D Multidimensional character Arrays, It doesnt appear like in a grid format i want it to.

#include<iostream>
#include<conio.h>
#include<string>
#include<cstdlib>
#include<ctime>


using namespace std;


int main ()
{
//A Message welcoming the user to minesweeper

cout<< "Welcome to Minesweeper!" <<endl;



char coveredarray [5][5] = {{'?','?','?','?','?'},
{'?','?','?','?','?'},
{'?','?','?','?','?'},
{'?','?','?','?','?'},
{'?','?','?','?','?'}},

for (int row=0; row;<5 row;++)
for(int column=0; column;<5); column;++)
cout<<coveredarray[row][column]<<" ");
Hi,

firstly, you have syntax errors on the following lines....


{'?','?','?','?','?'}}, for (int row=0; row;<5 row;++) cout<<coveredarray[row][column]<<" ");

Secondly, you should use the code tags to make it easier to read, like below. Note: I fixed the syntax errors

1
2
3
4
5
6
7
8
9
10
11
12
13
    char coveredarray [5][5] = {{'?','?','?','?','?'},
                                {'?','?','?','?','?'},
                                {'?','?','?','?','?'},
                                {'?','?','?','?','?'},
                                {'?','?','?','?','?'}};

    for(int row = 0; row < 5; row++)
    {
        for(int column = 0; column < 5; column++)
        {
            cout << coveredarray[row][column] << " ";
        }
    }



Lastly, it doesn't look like a grid because you aren't putting new lines in. A new line can be inserted like this:

cout << "This is the new line escape character\n";

The '\n' inserts a new line at the location. Alternatively, you can do it like this


cout << "The endl inserts a new line, AND it flushes the buffer" << endl;



Lastly, I recommend you read the following to help you understand loops and their syntax

http://www.cplusplus.com/doc/tutorial/control/



Best of luck.
Topic archived. No new replies allowed.