loop breaks

Write your question here.
so this code is doing something quite complicated..there is a global variable multiarray LN[800][5];
vector<int> hold contains certain values.

there is a class unit which create objects to hold the position of a value in
multiarray LN...and it got class functions getrow() and getcol which return an integer value of a row and a col...

there is a vector<unit> pst which holds unit(row, col) i want to keep track of...

so the program keeps on placing types unit in vector pst till pst has size 2 or more, then something has to be done...but it seems after the second if the program come out of the loop and carry on to terminate...
the idea is the first for loop should run to about 750 start from zero...
--> for (int r = 0; r < ROW-5; r++),,,but for a reason or so it stops abruptly..
can the more seasoned programmers pinpoint me in the right direction? thanks

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
  void cross_check()
{
  std:vector<int> hold;
  for(int i = 0; i < 5; i++)
   {
    if(LN[ROW-1][i] != 100)
     {
      hold.push_back(LN[ROW-1][i]);
     }
    if(LN[ROW-2][i] != 100)
     {
      hold.push_back(LN[ROW-2][i]);
     }
    if(LN[ROW][i] != 100)
     {
      hold.push_back(LN[ROW][i]);
     }
   }
   std::vector<unit> pst ;
   std::vector<int> two;

for(int n : hold)
    std::cout<<n<<" ";

   for (int r = 0; r < ROW-5; r++)
   {  for(int c = 0; c < 5; c++)
       {
        for(int n : hold)
        {
         if (LN[r][c] == n )
          {
            unit * pt = new unit(r, c) ;
            pst.push_back(*pt);
            delete pt;
          }
        }
       }

      if(pst.size() >= 2)    //after entry here it the program doesnt come back //out
     {
       signed int high = 0;
       signed int low = ROW;
        for(unit i : pst)
        {
           if(i.getrow() > high)
           { high = i.getrow() ; }
           if(i.getrow() < low)
           { low = i.getrow();}
        }
 
        for(int r = low-2 ; r < high+3; r++)
        { for(int c = 0; c < 5; c ++)
          {  bool presence ;
             for( unit n : pst)
             {  if(n.getrow() == r && n.getcol()== c)
                 { presence = true;
                 
                 }
             }
            if(!presence)
            {
              two.push_back(LN[r][c]) ;
          
            }
          }
        }
        pst.clear() ;
    }
}

first_rumble2(two)  ;
}
Last edited on
One obvious problem.
Line 53: presence is uninitialized. When you test it at line 60, you are testing garbage if a match wasn't found.
damn it! thanks man..the lil lil things are the one to get us ...
Topic archived. No new replies allowed.