Write in parts Finding one bug in the 20 lines you typed for the last fifteen minutes is easier than finding fifty bugs in the two thousands lines you have typed for one month. Good identifiers Use long identifiers such as sum_of_the_weights instead of short ones. Use longer identifiers for variables and functions used in many parts of the program. If a variable is used only in a 5 line loop, it can be called s with no risk. If you are really lazy, at least use acronyms (ws for weight sum for instance). Also, reuse the same names and parameter order everywhere. Avoid at all cost this sort of mess int rectangle_surface(int xmin, int ymin, int xmax, int ymax) { return (xmax - xmin) * (ymax - ymin); } int rectangle_diagonal_length(int xmin, int xmax, int ymin, int ymax) { return sqrt(double( (xmax - xmin) * (xmax - xmin) + (ymax - ymin) * (ymax - ymin) ) ); }
Learn C++ Programming fast and easy, find C++ Program Codes