Hello,
I have this function
void smallAverage(int *array, float *average, int *numSmallerThanAverage );
which returns in the parameters, average and numSmallerThanAvergae, the corresponding result. average is the average value of all the elements of the array. numSmallerThanAverage is the number of elements in the array which are smaller than the average.
Now, I need to test the function in a main routine and print the results. The main function must accept the size of the array as a command line parameter and the array should be initialized with random numbers.
Here is what I have so far from code, but I dont know why its doesnt work with me, and to be honest I'm new to C++ and I have no idea how to do a main routine, but I tried my best with the help of google :(
Please any help from anyone with that would be appreciated please!
#include <iostream>
#include <cmath>
#include <stdlib.h>
#include <time.h>
using namespace std;
/****************************************function # 1***********************************************/
void smallAverage(int *myArray, float *average, int *numSmallerThanAverage)
{
int size;
int sum = 0;
for(int i = 0; i < size; ++i){
sum += myArray[i];
}
*average = (float)sum/(float)size;
*numSmallerThanAverage = myArray[0];
for(int i = 0; i < size; i++)
cout << myArray[i] << " ";
for(int i = 1; i < size; i++) //check until condition i=size
{
if(*numSmallerThanAverage > myArray[i])
*numSmallerThanAverage = myArray[i];
}
cout << "\nSearching..." << endl;
//display the result...
cout << "The number of elements smaller than the average value is = " << *numSmallerThanAverage << endl;
}
int main(int argc, char* argv[])
{
int* myArray = NULL;
float* average;
int size;
cout << "Average: " << *average << '\n';
myArray = new int[size];
for(int i = 0; i < size; i++){
myArray[i] = 0;
}
delete[] myArray;
return 0;
}