My aim is to print out a grid of random characters, either a G, a W or an A. Here is my code (obviously with int main() etc):
Code:
srand(time(0));
char terrain[5][5];
for (int i = 0;i < 5; i++)
{
for (int j = 0;j < 5; j++)
{
int temp = (rand() % 2) + 1;
switch (temp)
{
case 1:
terrain[i][j] = 'G';
break;
case 2:
terrain[i][i] = 'W';
break;
default:
terrain[i][j] = 'A';
break;
}
}
}
for (int i = 0;i < 5; i++)
{
cout << "\n";
for (int j = 0;j < 5; j++)
{
cout << terrain[i][j] << "\t";
}
}
But the problem is a get some characters i want, plus i get some unexpected characters, i've played with the rand() function but i cant seem to figure out what im doing wrong, some help would be appreciated, thanks