I run the program and nothing prints out..

#include <iostream>
#include <vector>
#include <windows.h>
using namespace std;

void check_neighbors(vector<vector<char> >, int [22][88]);
void generation(vector<vector<char> >);
void display(vector<vector<char> >);

int main()
{
    vector<vector<char> > world(22, vector<char>(88, '.'));
    int neighborArray[22][80];

    //Intial condiion
    world[3][3] = '*';
    world[3][4] = '*';
    world[4][4] = '*';
    world[3][7] = '*';
    world[5][6] = '*';
    world[5][7] = '*';
    world[5][8] = '*';

    for(int c = 0; c < 3;c++)
    {
     //
    generation(world);
    cout << "here" << endl;
    Sleep(1000);
    display(world);
    }
    return 0;
}


void check_neighbors(vector<vector<char> > globe, int neighborArr[22][80])
{

    for(int i = 2;i < 20;i++)
    {


        for(int j = 2;j < 79;j++)
        {
                int neighbors = 0;
                if(globe[i+1][j+1]=='*')
                {
                    neighbors +=1;
                }
                if(globe[i][j-1]=='*')
                {
                    neighbors +=1;
                }
                if(globe[i+1][j-1]=='*')
                {
                    neighbors +=1;
                }
                if(globe[i-1][j]=='*')
                {
                    neighbors +=1;
                }
                if(globe[i-1][j+1]=='*')
                {
                    neighbors +=1;
                }
                if(globe[i][j+1]=='*')
                {
                    neighbors +=1;
                }
                if(globe[i+1][j-2]=='*')
                {
                    neighbors +=1;
                }
                if(globe[i+1][j]=='*')
                {
                    neighbors +=1;
                }
                neighborArr[i][j] = neighbors; //no errors in this method
        }
    }
}
void generation(vector<vector<char> > env)
{


    int neighborArray[22][80];
    for(int i = 0;i < env.size();i++)
    {
        check_neighbors(env, neighborArray); //error here, no erros above, no errors below

        for(int j = 0;j < env[i].size();j++)
        {

            if(env[i][j] == '*')
            {
               if(neighborArray[i][j] < 2)
               {
                   env[i][j] = '.';
               }
               if(neighborArray[i][j] > 3)
               {
                   env[i][j] = '.';
               }
            }
            else
            {
                if(neighborArray[i][j] = 3)
                {
                    env[i][j] = '*';
                }
            }
        }
    }
}

void display(vector<vector<char> > grid)
{
    for(int x = 0; x < grid.size(); x++)
    {
        for(int y = 0;y < grid[x].size();y++)
        {
            cout << grid[x][y];
        }
        cout << endl;
    }
}

Recommended Answers

All 2 Replies

Code in code tags please........

Have you checked that the vector of vectors is filled with the default dot values?

STL vectors are objects, not arrays. So when you pass a vector to a function it acts like an int or a char or a double. That means it can be passed either by value or by reference. If it is passed by value, then a copy of the vector is used in the function and the values of the copy are not visible/useable in the calling function. If you want the values of the vector passed to the function to change and you want the changes to remain in the calling function you need to pass the vector by reference.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.