1

I've just finished my homework program and I'm looking for any critiques. Whether they be about my methods, format of how the code is spaced and such, or anything of the sort. Also some ideas on decent commenting would be helpful.

In summary I'm trying to learn some good programming habits.

The assignment was to fill a 1 dimensional array with 5-10 numbers, compute the average, store the absolute deviation from the original numbers in another array. Then to print the Original array, average, deviated array, the largest deviation and least deviation. The largest and least had to also print their original value and the position in the array they occupy.

```
// CI_230_Assignment2.cpp : Defines the entry point for the console application.
//Assignment 2
#include "stdafx.h"
#include <iostream>
using namespace std;
#include <cmath>
//========================================================
void userInput( int size, float *input ){
cout << "Please enter " << size << " values: \n";
for( int i = 0; i < size; i++ ){
cin >> input[i];
}
}//end userInput
//========================================================
void find_average( int size, float &average, float *input ){//compute and return average according to const int SIZE, the determining var for size of array
float sum = 0.0;
for( int i = 0; i < size; i++ ){
sum = sum + input[i];
}
average = sum / size;
}//end_find_average
//========================================================
void fillDev( int size, float *average, float *input, float *deviation ){
for ( int i = 0; i < size; i++ ){
deviation[i] = abs( input[i] - *average );
}
}//end_fillDev
//========================================================
void find_deviation( int size, float *leastDev, float *largeDev, float *deviation, int *positionLeast, int *positionLarge ){
for ( int i = 0; i < size; i++ ){//finds the least and largest deviation and stores them in their respective variables
if ( deviation[i] > *largeDev ){
*largeDev = deviation[i];
*positionLarge = i;
}
else if ( deviation[i] < *leastDev ){
*leastDev = deviation[i];
*positionLeast = i;
}
}
}//end find_deviation
//========================================================
void output( int size, float *leastDev, float *largeDev, float *average,
float *input, float *deviation, int *positionLeast, int *positionLarge ){
cout << "\nOriginal Array: ";
for ( int i = 0; i < size; i++ ){//prints original array
cout << input[i] << " ";
}
cout << "\n\n" << "Average: " << *average << endl;
cout << "\nDeviation Array: ";
for ( int i = 0; i < size; i++ ){//Prints deviation array
cout << deviation[i] << " ";
}
cout << "\n\n" << "Largest Deviation: " << *largeDev << " belonging to "
<< input[*positionLarge] << " in position " << *positionLarge << " of Original Array." << "\n";
cout << "\n" << "Least Deviation: " << *leastDev << " belonging to "
<< input[*positionLeast] << " in position " << *positionLeast << " of Original Array." << "\n";
system("PAUSE > nul");
}//end_output
//========================================================
void main(){
const int SIZE = 10;
int positionLeast, positionLarge; //Holds which location of the array is the least deviation and greatest deviation respectivly
float average, leastDev = 999.0, largeDev = -999.0;
float input[SIZE];
float deviation[SIZE];
userInput( SIZE, input );
find_average( SIZE, average, input );
fillDev( SIZE, &average, input, deviation );
find_deviation( SIZE, &leastDev, &largeDev, deviation, &positionLeast, &positionLarge );
output( SIZE, &leastDev, &largeDev, &average, input, deviation, &positionLeast, &positionLarge );
}//end_main
```