Let us look at one part of your code, and you should get how to handle the error condition for division once you know how to structure this code:
First off, your indentation and formatting are really bad, and you need to improve that for many reasons, but for one, I find it hard to read...