/****
 *
 * This program computes simple statistics for numbers read from standard
 * input.  The program first asks for the number of values that the statistics
 * will be computed for.  The program then reads in that many values.
 *
 * The statistics computed are the sum of the numbers and the arithmetic mean.
 * The results are printed to standard output, in the following form:
 *
 * Sum = 
 * Mean =
 *
 * The precise formula for the mean is defined here:
 *
 *    http://www.gcseguide.co.uk/statistics_and_probability.htm
 *
 *
 * Author: Gene Fisher (gfisher@calpoly.edu)
 * Created: 14apr11
 * Last Modified: 14apr11
 *
 */

#include <stdio.h>
#include <math.h>

int main () {

    int n;                      /* Number of values to compute stats for */
    double x;                   /* Input value read from the terminal */
    double sum;                 /* Computed sum */
    int i;                      /* Loop counter variable */

    /*
     * Input the number of values, and prompt for the rest of the data values.
     */
    printf("Input the number of values you want to compute stats for: ");
    scanf("%d", &n);
    printf("Input the values, separated by whitespace: ");

    /*
     * Initialize the sum to 0.
     */
    sum = 0;

    /*
     * Initialize the loop counter to the number of data points.
     */
    i = n;

    /*
     * Loop until all the values are read in, accumulating the sum as we go.
     * Note that the loop will not go at all if the user enters a non-positive
     * value for the number of data points.
     */
    while (i > 0) {

        /*
         * Input the next value.
         */
        scanf("%lf", &x);

        /*
         * Increment the sum.
         */
        sum = sum + x;

         /*
          * Decrement the loop counter, so we'll stop after n inputs.
          */
        i = i - 1;

    }

    /*
     * Output the results.
     */
     printf("Sum = %f\n", sum);
     printf("Mean = %f\n", sum / n);

    return 0;

}

/***
 *
 * QUESTIONS:
 *
 *   1. Do we really need the loop counter variable i?  Couldn't we just
 *      decrement the value of variable n to know when to stop the loop?
 *
 *   2. How come we didn't use the function version of the stats program, i.e.,
 *      the version with compute_sum and compute_mean?
 *
 *   3. Why didn't we compute the standard deviation?  What would it take to do
 *      this?
 *
 */