Overthrown exception help

Hello everyone,

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)


/*

*/
#include "pch.h"
#include <iostream>
#include <fstream>
#include "screen.h"

using namespace std;

int seedWorld(char[30][120]); //set grid
void generation(char[30][120]);
void display(char[30][120]);

int main()
{
char world[30][120];
seedWorld(world);//perform this function
display(world);
delay(1.3);
}

int seedWorld(char world[30][120])
{
fstream file; //open file
file.open("starting life.txt", ios::in | ios::out);
int x, y, totalLines;
file >> totalLines;

for(int i = 0; totalLines < i; i++)
{
file >> x;
file >> y;
world[x][y] = 'o';
}
file.close();
return 0;
}

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).
*/
for(int i = 0; totalLines < i; i++) <-- Here, I think what you meant is the following instead:
for(int i = 0; i < totalLines; i++)

Also, next time please consider using code tags. It makes it easier for people to read your code.
if (world[x + 1][y] == 'o') will go out of index on the iteration x=29.

Make sure the inputs don't exceed 29 and 110.

Sorry I didn't have time to read your entire code properly but thought would reply anyway.
@Uk Marine and @Grime

Thank you very much! I was able to fix that problem of my code with your help!
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.

And put your code in code tags like you were asked to. http://www.cplusplus.com/forum/articles/16853/

Why should anyone help you when you aren't even trying?
Last edited on
Topic archived. No new replies allowed.