Use meaningful names for variables.
Be sure to check that variables are declared to be of the correct data type.
Be sure that variables are initialized before the program attempts to use their value. This can be done when the variable is declared or with an assignment statement before the variable is first used.
Use enough parentheses in arithmetic expressions to make the order of operations clear.
Always include a prompt line in a program whenever the user is expected to enter data from the keyboard, and always echo the user’s input.
An if-else
statement allows your program to choose one of two alternative actions. An if
statement allows your program to decide whether to perform some one particular action.
A do-while
loop always executes its loop body at least once. In some situations, a while
loop might not execute the body of the loop at all.
Almost all number constants in a program should be given meaningful names that can be used in place of the numbers. This can be done by using the modifier const
in a variable declaration.
Use an indenting, spacing, and line-break pattern similar to the sample programs.
Insert comments to explain major subsections or any unclear part of a program.