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.