Jump to content

  • Log In with Google      Sign In   
  • Create Account


Youbar

Member Since 12 Oct 2012
Offline Last Active Dec 07 2012 10:36 PM
-----

#5007939 (C++) Printing Out 2d Array

Posted by Youbar on 06 December 2012 - 06:15 PM


int map[5][5] =
{
1, 1, 1, 1, 1,
1, 0, 0, 0, 1,
1, 0, 2, 0, 1,
1, 0, 0, 0, 1,
1, 1, 1, 1, 1
};

int column = 0;
int column2 = 0;

()void print_map()
void print_map()
{
for (column = 0; column < 6; column++)
{
cout << map[column][column2];
if (column == 5)
{
  column2++;
  column = 0;
  cout << endl;
}
if (column && column2 == 5)
{
  break;
}
}
}
This is my code for printing out a 2d array.
What happens in the output though, is unexpected. It produces:

111110
00010
02010
00010
11110
1

Instead of:
11111
10001
10201
10001
11111

1. How can I fix this problem?
2. Can you call the an if command an exception?
3. Please don't post the fixed code. Just give me hints, unless the code is beyond fixing.


PARTNERS