1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
#include <iostream>
#include <cmath>
using namespace std;
int FillFunction(double []);
void PrintArray(const double [], int);
double findAverage (double array[], int size, double returnvalue);
const int MAXSIZE =100;
int main()
{
double array1[100];
int count;
count = FillFunction(array1);
cout<<"There is "<<count<<" numbers in this array"<<endl;
PrintArray(array1, count); //function call to function that will print the array
cout<<"The average of all these numbers is " << endl;
findAverage (double array[], int size, double returnvalue);
return 0;
}
//Write the function here to read in numbers into the array. The array is called myarray.
//add comments describing what this function does, what is passed to it, what it sends back, etc.
int FillFunction(double myarray[]){
using namespace std;
cout << "Enter no more than 100 positive numbers \n";
int next, index = 0;
cin >> next;
while (( next >= 0 ) && ( index < MAXSIZE )){
myarray[index]= next;
index++;
cin >> next;
}
return index;
}
//Write the new function here along with comments
//add comments describing what this function does, what is passed to it, what it sends back, etc.
void PrintArray(const double a1[], int size)
{
for ( int i =0; i < size; i++)
cout << a1[i] << " ";
cout<< endl;
}
double findAverage (double array[], int size, double returnvalue)
{
for(int i = 0; i < size; i++ ) {
returnvalue += array[ i ];
}
return (returnvalue / size );
}
I have to write a third function that will determine the average value in the array.. I have literally been working on this shit all day and cant figure it out haha.. Any help would be GREATLY appreciated
|