Do you have an algorithm for the program that you are trying to write code for?
Can you post it? The code has no comments describing how it is trying to solve the problem. Without them, it is...