loop counter not increasing

hi so im having some trouble with my code i made a counter that should display the cycle. counter doesnt start from 1 it starts at 50 and stays at 50. i dont know what im doing wrong

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
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <windows.h>
#include <time.h>
#include <stdlib.h>
#define ALIVE true
#define DEAD false
using namespace std;
const int ROWS = 24;
const int COLS = 79;
void Display(bool grid[ROWS][COLS])
{
    for(int a = 1; a < ROWS; a++){
        for(int b = 1; b < COLS; b++){
            if(grid[a][b] == true){
               cout << "Q";
            }
            else{
                cout << " ";
            }
 //           if(b == COLS){
 //               std::cout << std::endl;
 //           }

        }
        cout << endl;
    }

}

//This copy's the grid for comparision purposes.
void CopyGrid (bool grid[ROWS][COLS],bool grid2[ROWS][COLS]){
    for(int a =0; a < ROWS; a++){
        for(int b = 0; b < COLS; b++){grid2[a][b] = grid[a][b];}

    }

}
//Calculates Life or Death
void liveOrDie(bool grid[ROWS][COLS])
{

    bool grid2[ROWS][COLS] = {};
    CopyGrid(grid, grid2);
    for(int a = 1; a < ROWS-1; a++)
        {
        for(int b = 1; b < COLS-1; b++)
        {
            int neighbors = 0;
            for(int c = -1; c < 2; c++)
            {
                for(int d = -1; d < 2; d++)
                {
                    if(!(c == 0 && d == 0))
                    {
                        if(grid2[a+c][b+d]) {++neighbors;}
                    }
                }
            }

            if(neighbors < 2) {grid[a][b] = DEAD;}
            else if(neighbors == 3) {grid[a][b] = ALIVE;}
            else if(neighbors > 3) {grid[a][b] = DEAD;}

        }

    }
}

int main()

{
  srand(time(0));
    int counter;
    double fillPercentage;

    {
        for(counter = 0; counter < 50; counter++)
        {
            fillPercentage = (ALIVE/sizeof(COLS))*100;

        }
    }
    bool grid[ROWS][COLS] = {};

    grid[ROWS/2][COLS/2] = true;
    grid[ROWS/2-1][COLS/2] = true;
    grid[ROWS/2][COLS/2+1] = true;
    grid[ROWS/2][COLS/2-1] = true;
    grid[ROWS/2+1][COLS/2+1] = true;

                {

}

    while (true){


        Display(grid);     //This is our display.
        liveOrDie(grid); //calculate if it lives or dies.
        Sleep(500);
// std::cin.get();

cout << "\n" << fillPercentage << " cycle # " << counter << " Author: Bryan Euceda" << endl;
    }
return 0;

}
Last edited on
closed account (SECMoG1T)
Your program is full of loops all over, specifically which loop are we talking about
You are incrementing the counter in one loop and printing it in another loop. After the first loop the value of counter will be 50 and you never change it so it stays like that for the rest of the program.
Your program is full of loops all over, specifically which loop are we talking about
line 80 is the one im talking about sorry this code if for a game of life so it has a lot of loops
Topic archived. No new replies allowed.