Anyone knows whats up?

Its a game of life. Loads everything from inp.in.
Tough after the first step everything dies. Any ideas? Please explain if you have something, don't just do my work.
Here is what inp.in contains:
1 1 0 1 1
1 1 0 1 0
0 0 1 0 0
0 0 0 0 0

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
  #include <iostream>
#include <fstream>

using namespace std;
struct space
{
    bool state;
};
struct grid
{
    int sizes;
    space cell[100][100];
    void sSwitch(int x,int y)
    {
        cell[x][y].state=(cell[x][y].state==0);
    }
    int getmany(int x,int y)
    {
        int howmany=0;
        if(cell[(x-1)][y].state==1)
            howmany++;
        if(cell[(x-1)][(y-1)].state==1)
            howmany++;
        if(cell[(x-1)][(y+1)].state==1)
            howmany++;
        if(cell[(x)][(y-1)].state==1)
            howmany++;
        if(cell[(x)][(y+1)].state==1)
            howmany++;
        if(cell[(x+1)][y].state==1)
            howmany++;
        if(cell[(x+1)][(y+1)].state==1)
            howmany++;
        if(cell[(x+1)][(y+1)].state==1)
            howmany++;
    }
    int getcell(int x,int y)
    {
        return cell[x][y].state;
    }
    void showGrid()
    {
        for(int i=0; i<sizes; i++)
        {
            for(int j=0; j<sizes; j++)
                cout<<getcell(i,j)<<" ";
            cout<<endl;
        }
    }
    void showGridMany()
    {
        int a[100][100];
        for(int i=0; i<sizes; i++)
        {

            for(int j=0; j<sizes; j++)
            {
                a[i][j]=getmany(i,j);
                cout<<a[i][j]<<" ";
            }
        cout<<endl;
        }
    }
    void nextStep()
    {
        int a[100][100];
        for(int i=0; i<sizes; i++)
            for(int j=0; j<sizes; j++)
                a[i][j]=getmany(i,j);
        for(int i=0; i<sizes; i++)
        {
            for(int j=0; j<sizes; j++)
            {
                if(cell[i][j].state==1)
                {
                    if(a[i][j]<2)
                    {
                        sSwitch(i,j);
                        cout<<"Switched "<<i<<" "<<j<<endl;
                    }
                    if(a[i][j]>3)
                    {
                        sSwitch(i,j);
                    cout<<"Switched "<<i<<" "<<j<<endl;

                    }
                }
                else
                {
                    if(a[i][j]==3)
                    {
                        sSwitch(i,j);
                    cout<<"Switched "<<i<<" "<<j<<endl;
                    }
                }
            }
        }
    }
    void loadFrom(char name[255])
    {
        ifstream fin(name);
        for(int i=0; i<sizes; i++)
            for(int j=0; j<sizes; j++)
                fin>>cell[i][j].state;
    }
};
int main()
{
    grid mygrid;
    mygrid.sizes=5;
    mygrid.loadFrom("inp.in");
    mygrid.showGrid();
    cout<<"\n\n";
    cout<<mygrid.getmany(1,1)<<endl;
    mygrid.showGridMany();
    cout<<endl;
    mygrid.nextStep();
    mygrid.showGrid();
    return 0;
}
You forgot to return howmany from getmany.
Thanks man. Such a silly mistake I've made there. Thanks ;)
It was quite easy for me to spot because the compiler told me.

My compiler wrote:
test.cpp:36:5: warning: no return statement in function returning non-void [-Wreturn-type]

Most compilers are able to warn you about simple mistakes like this. If you're using GCC/MinGW/Clang I strongly recommend compiling the code with at least the -Wall compiler flag.

https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
I did get that warning as well, tough i ignored it xD
Though it is only a warning, it should be considered an error in most circumstances.
Here for example, if the call to function two() is uncommented, it will probably cause a program error.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <string>

using namespace std;

int one() { }

string two() { }

int main()
{
    cout << one() << '\n';
    // cout << two() << '\n'; this line probably cause a crash

    cout << "Done\n";
}


Topic archived. No new replies allowed.