creating a int 2-d array that holds characters


How would i create a 2d int array that hold these char symbols?

a 2D int [ROWS][COLS] array that would hold char symbols:
'.' for clear water
'S' for submarines (in DE_BUG mode)
'#' for sunk submarines
'n' where n is an integer representing the distance between a depth charge location to
the nearest live submarine.
Hello cash,

a 2D int [ROWS][COLS] array that would hold char symbols:
Yeah, how would I do this?
@cash

The only way I can think of, is fill the array with the values of the characters, as in..
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>

using namespace std;

int main()
{
	int grid[3][3]={{46,83,35},
	{50,46,46},
	{46,46,49}};
	// 46 = .
	// 49 to 57 = 1 thru 9
	// 35 = #
	// 83 = S
	for(int x=0;x<3;x++)
	{
		for(int y=0;y<3;y++)
		{
			cout << char(grid[x][y]) << " ";
		}
		cout << endl;
	}
	cout << endl;
    return 0;
}
Thanks this works, but how do you know which number correlates with which symbol.
I looked them up in an ASCII table. I wrote the values in the program for you, as well, lines 10 thru 13. In your program, you just check the value at the array location, and print accordingly.

1
2
3
if(grid[row][column] == 35)
  cout << "There is a sunk sub here." << endl;
// etc. 
Topic archived. No new replies allowed.