If within for loop, 'if' not activating

I have an input of one integer from 1 up to 100(lets call this N). Then another N number of boolean inputs (lets call this J). J is an array with the size of N

bool J[N] = {};

I would like to know how many boolean true (1) values "stand" next to each other.
So two trues after one another means one plus to the output.
The output is the number of paths between the true values.
for example:
0
0
1
1 - one here
1 - another one here
0
1
0
1
1 - and the last one here

Would mean the output is 3
but i get 0 as an output, which indicates to me that the 'if' didnt activate


1
2
3
4
5
6
7
for (z = 0; z < N ; z++)
            {
                if ((J[z] == true) && (J[z+1] == true))
                {
                    output++;
                }
            }


I used codeblocks
Last edited on
this part of the code is correct. the problem is elsewhere...
Maybe your input array is garbage then.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>

int main()
{
    const int N = 5;
    bool J[N] = { false, true, true, false, true };
    int output = 0;
    for (int z = 0; z < N ; z++)
            {
                if ((J[z] == true) && (J[z+1] == true))
                {
                    output++;
                }
            }
    std::cout << "Output=" << output << "\n";
}

Output=2

yepp seems like it was nothing to do with this loop..
thanks i worked it out, indeed the input array has been badly written
Topic archived. No new replies allowed.