First, you have to use Code tags while posting code snippets. Otherwise your code is unreadable! See Announcement: Before you post....
Second, you have to debug your code to see where, how and why something goes wrong. Set a break point at the beginning of the main(), then press F5 to start debugging, then F10 for each next step... and see the values of your variables in the watch window(s)...