This is a game of life lab due in a few hours and I have encountered an "overthrown exception" problem in visual studio. Can someone please tell me what's wrong and also proofread my code? The issue is at the line of
world[x][y] = 'o';
in the seedWorld function
(at the very end are the instructions)
void generation(char world[30][120])
{
int neighborsAlive = 0;
for (int x = 0; x < 30; x++)
{
for (int y = 0; y < 120; y++)
{
neighborsAlive = 0;
if (world[x + 1][y] == 'o')
neighborsAlive++;
if (world[x][y + 1] == 'o')
neighborsAlive++;
if (world[x + 1][y + 1] == 'o')
neighborsAlive++;
if (world[x + 1][y - 1] == 'o')
neighborsAlive++;
if (world[x][y - 1] == 'o')
neighborsAlive++;
if (world[x - 1][y] == 'o')
neighborsAlive++;
if (world[x - 1][y + 1] == 'o')
neighborsAlive++;
if (world[x - 1][y - 1] == 'o')
neighborsAlive++;
if (world[x][y] = 'o')
{
if (neighborsAlive < 2 || neighborsAlive == 3)
world[x][y] = ' '; //kill
else if (neighborsAlive == 2 || neighborsAlive == 3)
world[x][y] = 'o';//countinue life
if (neighborsAlive = 3 && world[x][y] == ' ')
world[x][y] = 'o';//come to life
}
}
}
}
void display(char world[30][120])
{
system("cls");
for(int x = 0; x < 120; x++)
for (int y = 0; y < 30; y++)
{
cout << world[y][x];
}
//time delay between each generation
}
/*
-Write a function called seedWorld that modifies your array (world)
with a starting configuration for living cells. The coordinates will
be read from a file called “starting life.txt”. Each line of this file
will have two numbers, the first representing the x coordinate and the
second representing the y coordinate of the living cell.
-Write a function named generation that modifies your array (world)
which contains the initial configuration. This function modifies the
cells (applies the rules).
-Write a function named display to write the contents of the array to
the screen. You will need to clear the screen for each display of a generation.
-A time delay is needed between each generation (ie applying the rules
and then displaying the changes).
*/
Stop starting new threads for the exact same topic.
You haven't even fixed the things pointed out in this thread.
Remove the checkmark on this thread and ask questions here if you're having problems.