displaying a multidimensional array as a table

I'm trying to display the contents of the array as a table, but the loop doesnt appear to be executing at all. Is there something I'm missing?


#include<iostream>
using namespace std;

int main()
{
int map[8][10];
int h = 0;
int w = 0;
char end = 0;

map[0][1] = 3;
map[0][6] = 2;
map[1][2] = 2;
map[6][8] = 1;
map[7][3] = 2;

for (h < 8;h++)
{
for (w < 10; w++;)
{
if (map[h][w] == 0)
cout << "_";
else if (map[h][w] == 1)
cout << "A";
else if (map[h][w] == 2)
cout << "E";
else if (map[h][w] == 3)
cout << "B";
else
{
cout << "error";
return 1;
}
}
}

cout << "press any key to continue" << endl;
cin >> end;

return 0;
}
One debug method is to add additional print commands (see below).
However, your code doesn't even compile:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include<iostream>

int main()
{
  using std::cout;

  int h = 0;
  int w = 0;

  for ( h < 8; h++ )  // warning: statement has no effect [-Wunused-value]
    // error: expected ';' before ')' token
  {
    cout << "h=" << h << " w=" << w;
    for ( w < 10; w++; ) // warning: statement has no effect [-Wunused-value]
    {
      cout << ", " << w;
    }
    cout << '\n';
  }
  return 0;
}
Last edited on
Topic archived. No new replies allowed.