1. ## Simple Array Functions

Hello,

I am trying to write a program that populates an array (10) with random values and then gets the Biggest Number, Smallest Number, and Average Value of those numbers.

Code:
// CalcArray.h

void InitializeArray(int *X)
{
int k,Holder;
k = 0;
while ( k < 10 )
{
Holder = rand()% 100;
if ( Holder > 9 )
{
k = k + 1;
*(X++) = Holder;
}
}
}

void TheSmallestValue(int *X, int *Y)
{

int k,Biggest,Holder;

Biggest = *X;

k = 0;
while ( k < 10 )
{

Holder = *(X++);
if ( Holder < Biggest )
{
Biggest = Holder;
}

k++;
}

*Y = Biggest;
}

void TheSmallestNumber()
{
int N[10];
int k;
int *P;
int BIG;

P = &N[0];

InitializeArray(P);
TheSmallestValue(P,&BIG);

cout << "\t\t\t The Smallest Member of the Array is = " << BIG;

cout << "\n\n\t\t\t The Values of the Array are :";

for ( k = 0; k < 10; k++)
{
cout <<"\n\t\t\t\t\t\t\t" << N[k];
}

}

void TheBiggestValue(int *X, int *Y)
{
int k,Biggest,Holder;

Biggest = *X;

k = 0;
while ( k < 10 )
{

Holder = *(X++);
if ( Holder > Biggest )
{
Biggest = Holder;
}

k++;
}

*Y = Biggest;

}

void TheLargestNumber()
{
int N[10];
int k;
int *P;
int BIG;

P = &N[0];

InitializeArray(P);
TheBiggestValue(P,&BIG);

cout << "\t\t\t The Biggest Member of the Array is = " << BIG;

cout << "\n\n\t\t\t The Values of the Array are :";

for ( k = 0; k < 10; k++)
{
cout << "\n\t\t\t\t\t\t\t" << N[k];
}

}

// main.cpp

#include "CalcArray.h"
#include <iostream>
#include <iomanip>
#include <cstdlib>

using namespace std;

int main()
{
TheLargestNumber();
TheSmallestNumber();

}
Now my question is, how would I get the Average Value of all the numbers? I have been trying different things and nothing is working.

2. Is all that code really in a .h file? That should not be the case. You should have the prototypes in the .h file, the implementation in a CalcArray.cpp file, include CalcArray.h in the .cpp files and compile and link all the .cpp files together.

As far as calculating the average, how would you do in on paper with a list of numbers?

3. After I put it on a piece of paper and thought about it for a while I figured it out. And I will follow your suggestions for the functions. Thanks.