Displaying a 2-dimensional array

I'm trying to display a graph with modified characters.

So, when my function goes through the two-dimensional array, it replaces '1' with '#' and replaces '0' with a space (' ').

Here is what I have so far:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
using namespace std;

void displayGraph(int map[6][6]) {
    for (int x = 0; x < 7; x++) {
        for (int y = 0; y < 7; y++) {
            if (map[x][y] == 1) {
				cout << "#" << endl;}
			else if (map[x][y] == 0) {
				cout << " " << endl;
            }
        }
    }
    return;
}

int map[6][6] = {
{1, 1, 1, 1, 1, 1},
{1, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 1},
{1, 1, 1, 1, 1, 1}
};

int main()
{
	displayGraph(map);

	system("PAUSE");
	return 0;
}


I want the output to be:
######
#    #
#    #
#    #
#    #
######


But that's not what I'm getting for some reason, can someone help me?
1
2
3
4
5
           if (map[x][y] == 1) {
				cout << "#" << endl;}
			else if (map[x][y] == 0) {
				cout << " " << endl;
 


Whenever it gets a 1 or a 0 regardless of it's place in the matrix, it's sending an end line (endl) after printing the replacement character. I suspect you're seeing a column of '#'s with empty lines between and an occasional two lines of '#'.

You want to output a endl after the inner loop ends, not within it.
Last edited on
Ah, yes.
Alright I got it, thanks :)
Topic archived. No new replies allowed.