/* Filename:  array1.cpp

   Author:  Br. David Carlson

   Date:  January 6, 2000

   Modified:  June 26, 2000; August 20, 2001

   This program prompts the user to enter integers into an array (by
   first asking the user for the number of integers to be entered).
   The number of integers can be no more than 10.  It then computes
   and prints the average of the integers.

   Tested with:
      Microsoft Visual C++ 6.0
      Microsoft Visual C++ .NET
      g++ under Linux
*/

#include <iostream>
using namespace std;


const int ArrayMax = 10;   // Change this to whatever is appropriate.

typedef int ArrayType[ArrayMax];


// Function prototypes:

float FindAverage(ArrayType NumArray, int Count);

void FillArray(ArrayType NumArray, int & Count);


int main(void)
   {
   int NumItems;
   ArrayType MyArray;
   float Avg;

   FillArray(MyArray, NumItems);
   Avg = FindAverage(MyArray, NumItems);
   cout << endl << "The average is: " << Avg << endl << endl;

   return 0;
   }


/* Given:   Nothing.
   Task:    To ask the user for the Count of how many integers to enter
            and to get the user to enter these integers.
   Return:  NumArray  The array of integers entered by the user.
            Count     The number of such integers entered.
*/
void FillArray(ArrayType NumArray, int & Count)
   {
   int k;

   cout << "How many items would you like to enter? ";
   cin >> Count;

   for (k = 0; k < Count; k++)
      {
      cout << "Enter array item for index " << k << " ";
      cin >> NumArray[k];
      }
   }


/* Given:   NumArray   An array of Count integers stored contiguously 
                       from index 0 onward.
            Count      The number of integers in NumArray.
   Task:    To find the average of the numbers in NumArray.
   Return:  This average in the function name.
*/
float FindAverage(ArrayType NumArray, int Count)
   {
   int k;
   float Sum;

   Sum = 0.0;
   for (k = 0; k < Count; k++)
      Sum = Sum + NumArray[k];

   if (Count > 0)
      return Sum / Count;
   else
      return 0.0;
   }


