#include <iostream>
#include <vector>
#include <numeric>
usingnamespace std;
// Function Declarations
float average(vector<int>&);
// average - calculates average value in vector
void print(float);
// print - prints averageValue
// @param float - averageValue to print
// Initiate values
int sum = 0;
int i=0;
double averageValue;
int main()
{
// Initiating vector
vector <int> vectorValues(10);
// Initiating loop, vector size is zero
// if i less than ten count up
for (vector<int>::size_type i=0; i < 10; i++)
{
// Flush makes sure that the buffer is cleared and the characters are written to their destination
cout << "Enter value to vector #" << i+1 << ": " << flush;
// Enter values into vector
cin >> vectorValues[i];
}
average(vectorValues);
print(averageValue);
return 0;
}
float average(vector<int>& vectorValues)
{
for (i = 0; i > vectorValues.size(); i++)
{
sum += vectorValues[i];
}
// Adding values from vector into variable sum
// sum = vectorValues[0] + vectorValues[1] + vectorValues[2] + vectorValues[3] + vectorValues[4] + vectorValues[5] + vectorValues[6] + vectorValues[7] + vectorValues[8] + vectorValues[9];
// Calculating average value
averageValue = (float) sum / vectorValues.size();
return averageValue;
}
void print(float averageValue)
{
// Print average value
cout << endl;
cout << "Average value " << averageValue << endl;
}