Ey all.

Im folowing a c++ course and im stuck writing string or char arrays to matrices.

The problem is i have a matrix of size [j] with random values from 0 to 3.
Each of these values have to correspond to either a string or char array.

0=EMPTY
1=RES
2=SUS
3=KILL

Now i want to know if it is possible to either make use of enumarations since they already correspond to integer values like.

``enum CELLTYPE {EMPTY, RES,SUS, KILL}``

and then seed them in matrix randomly put i dont know how to do this.

I think it's much easier to just first seed matrix with 0 to 4 which i know how to do.
But then i cant convert the values to string or char. gives me error cant convert int to char if i do it like this.

``````char usergrid(int rows, int col, int world[10][10])
{
cout << endl;

char EMPTY[] = "EMPTY";
char SUS[] = "SUS";
//string RES = "RES";
//string KILL = "KILL";

for(int i=0; i < rows ; ++i)
{
for(int j=0; j < col; ++j)
{
if (world[i][j] == 0)
world[i][j] = EMPTY;
else if  (world[i][j] == 1)
world[i][j] = SUS;
else if (world[i][j] == 2)
//world[i][j] = RES;
else if (world[i][j] == 3)
//world[i][j] = KILL;
}
}
for(int i=0; i < rows ; ++i)
{
for(int j=0; j < col; ++j)
cout << world[i][j] << "\t";
cout << endl;
}

return world[10][10];
}``````

plz help!!!!

Ey all.

Im folowing a c++ course and im stuck writing string or char arrays to matrices.

The problem is i have a matrix of size [j] with random values from 0 to 3.
Each of these values have to correspond to either a string or char array.

0=EMPTY
1=RES
2=SUS
3=KILL

Now i want to know if it is possible to either make use of enumarations since they already correspond to integer values like.

``enum CELLTYPE {EMPTY, RES,SUS, KILL}``

and then seed them in matrix randomly put i dont know how to do this.

I think it's much easier to just first seed matrix with 0 to 4 which i know how to do.
But then i cant convert the values to string or char. gives me error cant convert int to char if i do it like this.

``````char usergrid(int rows, int col, int world[10][10])
{
cout << endl;

char EMPTY[] = "EMPTY";
char SUS[] = "SUS";
//string RES = "RES";
//string KILL = "KILL";

for(int i=0; i < rows ; ++i)
{
for(int j=0; j < col; ++j)
{
if (world[i][j] == 0)
world[i][j] = EMPTY;
else if  (world[i][j] == 1)
world[i][j] = SUS;
else if (world[i][j] == 2)
//world[i][j] = RES;
else if (world[i][j] == 3)
//world[i][j] = KILL;
}
}
for(int i=0; i < rows ; ++i)
{
for(int j=0; j < col; ++j)
cout << world[i][j] << "\t";
cout << endl;
}

return world[10][10];
}``````

plz help!!!!

Use a 2D array of strings instead of integers, and populate it with the proper text as you generate the random numbers

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.