Question: I have a run time issue when i debugged my script.

It says :

```
Unhandled exception at 0x002a4f8e in test2.exe: 0xC0000094: Integer division by zero.

```

Although the line in question is a rand number generation.

```
if((rand() % miss) < 3){ //line 40
  int phit = (rand()% hit);
} else {
  bool pmiss = true;
} 

```

Debugger stops at line 40 when it goes wrong (which i labelled above).

My full script is here:
<http://www.paste.to/MzQ1ODM1>

How should I have written the if statement if this causes such an error, i keep thinking like a PHP programmer which is v.frustrating to adapt!

Answer: 
line 29 and 32 should be

```
miss = 5

miss = 2

```

you are declaring a new local variable miss inside the if scope which means you are not changing the one declared at line 6
The % (modulus) is the remnant of the division. So you divide a by b in a%b and get the remnant from it. If b is 0 (like in this case), you get an error.  

Division by 0 is illegal and causes a cosmic disturbance (or code crash).  

try setting the variable to another value.