enumeration array help

need help assigning the cells in this 2d array to '*' which is the initial value in the enum

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
33
34
35
36
37
38
39
40
41
42
43
  #include <iostream> 
using namespace std;

const int SIZE = 5;
enum Symbols {INITIAL = '*', BOMB = '@', EXPLOSION = 'X'};
void student_info();
void game_info(int mines);
void setupBoard(Symbols gameboard[][SIZE]);


//*****************************************************************************
int main()
{
	Symbols gameboard[SIZE][SIZE];	
	
	setupBoard(gameboard);  //having issues
	
	//printing out array to check if it's working after setting all positions to * / initial
	for(int i = 0; i < SIZE; i++)
	{
		for(int j=0; j<SIZE; j++) //This loops on the columns
		{
			cout << gameboard[i][j]  << "  ";
		}
		cout << endl;
	}	
	return 0;
}

//function to assign every value in 2d array to '*' aka INITIAL in enum
void setupBoard(Symbols gameboard[][SIZE])
{
	int row, col;
	
	for(int row; row < SIZE; row++)
	{
		for(int col; col < SIZE; col++)
		{
			gameboard[row][col] = INITIAL;
		}
	}	
}
enums turn into ints.

so when you fill the array of *enums* you fill it with ints, or the ascii value of the characters you used.

the quick fix is to make this
Symbols gameboard[SIZE][SIZE];
into this
char gameboard[SIZE][SIZE];

there are other ways but that should let you print the thing and see what you want to see. Just remember that char arrays print until a 0 char is reached so you might want:
char gameboard[SIZE][SIZE+1];
and
for(dx = 0....... size)
gameboard[dx][size] = 0; //set the end of string on all of the rows so you can just print them with a cout statement easily.




Last edited on
OP: also check-out this similar post:
http://www.cplusplus.com/forum/beginner/212955/
Topic archived. No new replies allowed.