Also, there is a curly bracket missing somewhere, so this code cannot be real.

My advice : user proper indentation, keep things simple, think before you code, and improve your knowledge of C/C++ syntax.

Instead of asking "why is this" in a forum, step through your code and you will see what your code does.

Regards,
Marc