Hello,
It sounds like you are just learning how to code. Welcome to a wonderful world of coding, debugging, and upkeep.
As long as you are just starting, you may want to remember a few things..... this will help you in the long run:
1) COMMENT. Write out in comments what you want that segment of code to do. Don't think it is silly or redundant... not even COBOL is super descriptive of what the code below should be doing. In your comments, put down what the variables represent, and what you want the code to do with them. Also, as you maintain the code, update your comments.
2) STYLE. Choose names of variables that mean something. For example, if your variable represents an amount of beans in a jar, call that variable beansinjar or something like that. Be careful of case sensitivity... depending on compilers, beans and BEANS could be different variables. Also, space your code out, and use the tab key to block out functions and loops. Your code should be easy to read.
3) FUNCTIONS DO SMALL THINGS. Do not overload what a function does, or you will remove flexibility as the code developes. Have each function only do one small part of the puzzle. A function might open a file, or output to the file. Don't try to have the function save the day.
4) ERROR-CHECK your input values. Don't assume good data will flow into your system. Check for data out-of-bounds, or for numbers that should be letters, etc. Wrong data will just blow up the program (best case) or will allow it to work with garbage results (worst case), as you will get results, but have no idea that the computations may be wrong.
As you continue to code, you will develop wisdom and templates on how your code will grow.
Good luck!
Christian
Reputation Points: 121
Solved Threads: 57
Posting Virtuoso
Offline 1,629 posts
since Mar 2004