Loop problems
Oct 25, 2011 at 10:23pm UTC
Unhandled exception at 0x779015ee in hw7.exe: 0xC0000005: Access violation reading location 0x33612bd4.
I am unsure of what this error means. Could someone help me with this issue? Let me know if i need to post the code.
EDIT: I have located where the error is occuring. It is skipping the for loop entirely and moving back to the main function.
The code is below.
HEIGHT and WIDTH are defined as global constants.
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
bool fall = false ;
const int MAX_STEPS = 42;
int prevX = Willie.m_Xcoord;
int prevY = Willie.m_Ycoord;
int nextX, nextY, moveWillie;
result stats;
Location spot;
for (int i = 0; (i < MAX_STEPS) && (fall = false ); i++)
{
switch (rand()%4)
{
case LEFT:
nextX = prevX - 1;
nextY = prevY;
break ;
case RIGHT:
nextX = prevX + 1;
nextY = prevY;
break ;
case DOWN:
nextX = prevX;
nextY = prevY + 1;
break ;
case UP:
nextX= prevX;
nextY = prevY - 1;
break ;
}
if (nextY >= 0 && nextY < HEIGHT && nextX >= 0 && nextX < WIDTH)
{
switch (school[nextX][nextY])
{
case EMPTY:
school[prevX][prevY] = EMPTY;
school[nextX][nextY] = WILLIE;
stats.outcome = 0;
break ;
case WALL:
school[nextX][nextY] = WALL;
school[prevX][prevY] = WILLIE;
stats.outcome = 0;
stats.bruise++;
break ;
case WINDOW:
school[nextX][nextY] = WINDOW;
school[prevX][prevY] = EMPTY;
fall = true ;
stats.outcome = 1;
break ;
case LUNCH:
school[nextX][nextY] = WILLIE;
school[prevX][prevY] = EMPTY;
fall = true ;
stats.outcome = 2;
break ;
}
}
}
return stats;
}
Last edited on Oct 26, 2011 at 12:04am UTC
Oct 26, 2011 at 9:17am UTC
(fall = false )
You must write ==
for comparisons. =
is for asignments
Topic archived. No new replies allowed.