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: 
You are re-declaring `miss` at line 30. That variable will be local to the *if* statement. *Therefore, the global `miss` will still have a value of zero.* Take out all those `int`, and also the `bool` inside the `if` statements! Like this:

```
                            if(user_weapon == 'k'){
                                    miss = 5;
                                    hit = 5;
                            } else if(user_weapon == 'b'){
                                    miss = 2;
                                    hit = 3;
                            } else {
                                    invalid = true;
                            }

```
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