Alright, being charitable, that code is a little wild. I’ve cleaned it up a bit, the key changes were to replace all occurrences of Wald
with Forest
and to change the array access to access Forest
in main. The code generates a character table printForest
prints out the table row by row, I hope that’s what you were after 🙂
#include <iostream>
void printForest();
static const int maxRows = 20;
static const int maxColumns = 30;
char Forest [maxRows][maxColumns];
int main ()
{
int tree, line, column;
srand(time(NULL));
for (line = 0 ; line < maxRows; line++)
{
for (column = 0; column < maxColumns; column++)
{
tree = rand() % 100 + 1;
if (tree > 0.6 * 100)
Forest[line][column] = ' ';
else
Forest[line][column] = 'X';
}
}
printForest();
std::cin.get();
return 0;
}
void printForest()
{
int line, column;
for (line = 0 ; line < maxRows; line++)
{
for (column = 0; column < maxColumns; column++)
{
std::cout << Forest[line][column];
}
std::cout << std::endl;
}
}
1
solved C++ Compiler shows just numbers, not the right output [closed]