The program is supposed to show how you can send an array into a function without making a loop to run the function once per value...
Code: Select all
#include <iostream>
//Program to calculate the average of 5 elements, as per copied from the book
double Average (int *ListValues, int Elements);
void main ()
{
int Values[5];
int NumberValues;
for(NumberValues=0;NumberValues<5;NumberValues++)
{
std::cout<<"Enter Value\n";
std::cin>>Values[NumberValues];
}
double AverageValues;
AverageValues = Average (Values, 5);
std::cout<<"The average of all values is "<<AverageValues<<"\n";
}
double Average (int *ListValues, int Elements)
{
double Total = 0;
int NumberElement;
for(NumberElement=0 ; NumberElement < Elements;NumberElement++);
{
Total += ListValues[NumberElement];
}
return Total / Elements;
}
My skills are almost up to scratch to start heavy coding, just need to brush up on pointers and classes, since i know most operators, variable and array syntax etc...