C++ for loop infinite

Hello all..
I am currently stuck on this for loop.. When ran, it keeps going and I need to stop.. Thanks in advance!

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
 FOR (i=0; i<199; i++)
{


  FOR (J=0;J<500; J++)
    IF (J=0)
    {
    DIST_WALKED = INIT_WALK_DIST + J
    }
    ELSE
    {
    DIST_WALKED = DIST_WALKED + ([(i * 214013 + 2531011)%2147483647] % 200) + 100;
    }

    // DETERMINE DIRECTION OF WALK
      IF (MOD(J) = 7)
      {
       DIRECTION = COMPASS_PREV * COMPASS_PREV2 *COMPASS_PREV3 * COMPASS_PREV4 * (COMPASS_INDEX)
      }
      ELSE
      {
      DIRECTION = COMPASS_NEXT * COMPASS_NEXT2 * COMPASS_NEXT3 * COMPASS_NEXT4 * (COMPASS_INDEX)
      }

    // DETERMINE XY COORDINATES
    IF (DIRECTION = "N" || DIRECTION = 2)
    {
        POS_X = POS_X + ( DIST_WALKED * COMPASS_NEXT * COMPASS_NEXT2 * COMPASS_NEXT3 * COMPASS_NEXT4(COMPASS_INDEX))
        POS_Y = POS_Y
    }
    IF (COMPASS_INDEX = 1 || COMPASS_INDEX = 3)
    {
        POS_X = POS_X
        POS_Y = POS_Y + ( DIST_WALKED * COMPASS_NEXT * COMPASS_NEXT2 * COMPASS_NEXT3 * COMPASS_NEXT4(COMPASS_INDEX))
    }


    // CALC DIST FROM HOME
    DIST_HOME = sqrt((HOME_X - POS_X)^2 +(HOME_Y-POS_Y)^2);

    //CALC DIST FROM NICK
    DIST_NICK = sqrt((NICK_X - POS_X)^2 +(NICK_Y-POS_Y)^2);

    //CHECK PROXIMITY TO HOME
    if (DIST_HOME <= 30 && J > 5)
    {
      cout<<"You are home!"<<endl;
    }
    else if (DIST_HOME >= 5280)
    {
      DIST_HOME = DIST_HOME /5280;

    }

    // CHECK PROXIMITY TO NICKS
    if (DIST_NICK <= 50)
    {
      cout<<"You are close to Nick's house!"<<endl;
    }
      else if (DIST_NICK >= 5280)
    {
      DIST_NICK = DIST_NICK / 5280;
    }
}
Hello.

You're mixing up '=' and '=='.
a=2 'a' will be 2.
if(a == 2) {
//means if 'a' is the same as 2.
//do something, if 'a' is 2 and only 2.
}
It won't change 'a'.

Regards
Last edited on
that was my issue!

Thanks for your help!
Usually, identifiers in ALL_CAPS are reserved for macros.
Because macros (especially function-like macros) have unpredictable semantics, it is important to maintain the distinction between them. Mistaking a identifier for a function or variable name when it is actually a macro can result in code that silently does the wrong thing.

Although maybe your code isn't actually in ALL_CAPS at all, because the language is case-sensitive.
Topic archived. No new replies allowed.