// Example use of vectors
// The mean of a  vector  of  10 integer values  is
// calculated, then elements that have a value less
// than the mean are removed from the vector.

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{

    unsigned int i, sum=0;
    vector<int> iv;

    // Push arbitrary values to the vector
    for ( i=10; i<20; i++ ) {
      int k = i*(i+8) % 30;
      iv.push_back(k);
    }

    // Show the vector
    cout << "Vector iv = ";
    for( i=0; i<iv.size(); i++ ) cout << iv[i] << " ";
    cout << endl;

    // Calculate the mean of the values
    for( i=0; i<iv.size(); i++ ) sum = sum + iv[i];
    double mean = double(sum) / iv.size();

    // Remove elements that have values less than the mean
    cout << "Removing values less than " << mean << endl;
    for ( i=0; i<iv.size(); i++ ) {
      if ( iv[i] < mean ) {
        iv.erase( iv.begin()+i );
        i--;
      }
    }

    // Show the reduced vector
    cout << "Vector iv = ";
    for( i=0; i<iv.size(); i++ ) cout << iv[i] << " ";
    cout << endl;

    return 0;
}
