c++ code giving obscure results

Hi! This is my first time posting in here, so please don't hate me if I do something wrong :)

I have been coding a collision detection program, but I have noticed some strange results occurring with one of my methods of my class. To be precise when I input the coordinates of my rectangle shape my function AssignTopLeftCorner seems to give random results. What is even stranger is that when debugging I included 'cout' and 'getch()' commands. After I included the getch command my program started working properly again, without changing any other code whatsoever! I have tried the same .exe on a different computer and it worked fine. I have no idea what is going on. Here is a code for my method:

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
void shape::AssignTopLeftCorner()
//assigns a top left corner as a first in the
//array (this is imporant for my collision detection functions)
{
  //   cout<<"initial values for assigntopleftcorner: ";
   // for(int i=0;i<8;i++)
  //  cout<<verticies[i/2][i%2]<<", ";
  //   cout<<endl;
  //   getch();
 //cout<<"assign test"<<endl;
     if (type=='C') return;
    int temp[4][2];
     temp[0][0]=verticies[0][0];
     temp[0][1]=verticies[0][1];    
     int topLeft;
     if (type=='S')
     {       
        for (int i=1; i<4; i++)
        {            
            if (verticies[i][0]<temp[0][0] || verticies[i][1]>temp[0][1])
            {
                  topLeft=i;
                  temp[0][0]=verticies[i][0];
                  temp[0][1]=verticies[i][1];
            }
        }            
     }
     if (type=='R')
     {
        for(int i=1; i<4; i++)
        {
                if(verticies[i][1]>temp[0][i])
                {
                  topLeft=i;
                  temp[0][0]=verticies[i][0];
                  temp[0][1]=verticies[i][1];
                }
        }
     } 
     for (int i=1; i<4; i++)
            {
                temp[i][0]=verticies[(topLeft+i)%4][0];
                temp[i][1]=verticies[(topLeft+i)%4][1];
            }
     Change(temp);
   // cout<<"final values for assigntopleftcorner: ";
   //  for(int i=0;i<8;i++)
   //  cout<<verticies[i/2][i%2]<<", ";
   //  cout<<endl;
   //  getch();
}


This is only a part of my code and I guess its of no use without a full code, but I have read that I am not supposed to copy and paste full programs, so I will send it on request.
I have no idea why adding a simple getch() command would solve this issue.
Thank you in advance :)
I can't see anything that would change by adding std::couts and getch()s for debugging (unless there's something in Change that has to do with input).

It's possible that you'd having some screwy things happen with your program accessing memory that it doesn't own but isn't reserved by another program somewhere else in your code.

-Albatross
Thanks for the reply!
Upon further investigation it is actually line 6 and 7 that are crutial in here. It seems that only when I read the numbers from the array the program stars working normally. This is indeed very strange and has happened to me for the first time...
This topic is just computer dependant, so I'll just assume that my computer is dying D: solved?
Topic archived. No new replies allowed.