Writing a program can be a lot of fun. In many ways it is like solving a puzzle. You will wrestle with a program, with the complier, with the computer, but when you finally get it working you will feel... well wait and see, it's too great a feeling to describe.
Writing a program can also be a very mysterious process. At first you will write code that doesn't work, then you will make a seemingly random change -- maybe just changing one line or one word or even just one punctuation mark -- and suddenly the program will work. And you won't know why. Learning how to program can be very confusing. You may feel like you are writing random statements, not really knowing what you are doing. This is normal, and it will get better. One day the light will dawn.
One way to avoid wasting a lot of time hacking is to spend time thinking about your program away from the computer before you start programming.
Often, you will read the assignment and think that you understand it well enough to program it, so you start writing right away. You get halfway into the program and you realize that there are many issues that you didn't consider before your started. Complexities that you didn't realize were part of the solution. But you have already started the program, so you don't want to throw away the code you've written, no matter how badly it fits the solution. So you continue trying to patch in new functions and new code, desparate to make it work. This technique never works
If only you had taken the time to think through your program before you started working, you would have discovered the tricky parts and would have planned for them from the beginning. Preplanning, desiging an algorithm before you code, is an essential step in writing a working program.
The reason this step must be done away from the keyboard is that thinking about a new program is exciting. When you think you know the first step of the solution, you want to write the code right away, and so you start typing before you have thought the whole algorithm through. It happens to everyone.
Here are 10 steps for doing your homework. I will be much more able (and more willing) to help you if you are on step 4 or 5.