I shaved down the code a bit. Can anyone tell me how to get the sides of the minefield to display correctly?
Thanks
#include <iostream>
using namespace std;
void main()
{
const int size = 20;
int x, y,count;
char array[size][size];
for (int i = 0; i < size; i++)
for (int j = 0; j < size; j++)
array[i][j] = '.';
srand(2202); //Set a random number seed.
for (int i = 0; i < size * size * 0.1; i++) //Placing mines in 10% of the field.
{
x = rand() % size;
y = rand() % size;
array[x][y] = '#';
}
for (int i = 1; i < size; i++)
for (int j = 1; j < size; j++) // Counting mines in 8 areas surrounding each index.
{
count = 0;
if (array[i][j] == '#')
continue;
if (array[i - 1][j - 1] == '#')
count++;
if (array[i - 1][j] == '#')
count++;
if (array[i - 1][j + 1] == '#')
count++;
if (array[i][j - 1] == '#')
count++;
if (array[i][j + 1] == '#')
count++;
if (array[i + 1][j - 1] == '#')
count++;
if (array[i + 1][j] == '#')
count++;
if (array[i + 1][j + 1] == '#')
count++;
array[i][j] = '0' + count;
}
for (int i = 0; i < size; i++) //Displaying MineField.
{
for (int j = 0; j < size; j++)
cout << array[i][j];
cout << " \n ";
}
}