GUIDELINES FOR PROGRAMMING LANGUAGES ASSIGNMENTS A) Indent your code to show the program structure. The style I favour is exemplified by the code appended below but there are many possible ways of doing indentation and placing the braces - the important thing is that you should pick one style and be consistent in using it. B) Use meaningful variable names. Single letter variable names such as 'i' are fine for obvious things like loop counters but most variables should be at least 3 characters long and should have a name related to their use in the program. C) Avoid use of file-scope variables and (especially) global variables except where absolutely necessary. The instructions to the assignment will usually make it clear if file-scope variables are to be used. In general, variables should be defined at the smallest scope possible. D) Comment your code. Each function should have a "header comment" that explains the purpose of the function, its inputs, outputs, and return value. Extra comments should appear inside the function to explain any code which is less than obvious. E) Follow the instructions for the assignment precisely ! Eg. if the assignment says to have a function that takes three float parameters - don't use an array with three elements instead. Don't solve a more general problem than was posed - this makes difficulties for the marker in trying to compare with the other students' work. /*************************************************************************** NAME: calc_average(int values[], int num_values) INPUT: values : array of non-negative values num_values : number of values OUTPUT: --- RETURN: float : average of the values DESCRIPTION: Calculates the average of the array of values. Exits the program with an error message if any of the values is negative. ---------------------------------------------------------------------------*/ float calc_average(int values[], int num_values) { int sum = 0; for (int i = 0; i < num_values; i++) { if (values[i] >= 0) { sum += values[i]; } else { // Negative values are a fatal error cerr << "Error: value #" << i << " is negative (" << values[i] << ")\n"; exit(1); } } float avg = static_cast(sum) / num_values; return avg; }