Send Close Add comments: (status displays here)
Got it!  This site uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website.nbsp; Note: This appears on each machine/browser from which this site is accessed.
Style comments


1. Style comments
This page has style comments.

Going forward, A3 and after, these (and other) deductions will be made.

2. Multiple blank lines
Avoid multiple blank lines in program code. The extra blank lines are not needed.

3. Output statements

4. Comments

/*    This is a good    multi-line comment form */


/* This is a not good multi-line comment form */


// This is a good single line comment form //This is a not good single line comment form

Only include comments that add value to the reader. The reader understands C, and understands the problem. Good comment: (no comment)
   double map_distance;

Not good comment: (not needed, obvious)
   // this is the map distance    double map_distance;


5. Header comments

6. Variable names
Use meaningful names for most variables.

A variable name should always refer to what it represents.

7. Indentation

8. Indentation rule
Rule: Do not mix tabs and spaces in the left white space indentation.
... ... {    ...    ... {       ...       }    ... {       ...       }    } ...


9. Customer facing input and output
All customer-facing input and output should match exactly the provided input and output examples. This constitutes the functional requirements.

10. Specific requirements
Some works have very specific requirements and deductions specific to that work.

11. Minimal code
In a good program, everything there is needed and important.

Anything not needed should be removed.
   int i1 = 0;    // code not using i1    i1 = 10;

In the above code, variable i1 is declared and initialized to 0. But then it is set to 10. So a better way would be as follows, where declarations are separated from input/processing.
   int i1;    // code not using i1    i1 = 10;


12. Input using scanf
scanf("%d,%d", &x1, &x2);

good: (accepts any double number)
   double x1;    scanf("%lf", x1);

not good: (only accepts numbers with two places past the decimal point)
   double x1;    scanf("%0.2lf", x1);

good: (reads two double numbers)
   double x1;    scanf("%lf %lf", &x1, &x2);

not good: (comma is required in the input, else second value becomes 0.0)
   double x1;    scanf("%lf,%lf", &x1, &x2);


13. Strings
Declare string s1 and (single) character s2.
char s1[256], s2;

Declare (single) character s1 and string s2.
char s1, s2[256];

Declare string s1 and string s2.
char s1[256], s2[256];


14. End of page

15. Multiple choice questions for this page