title: Calculating average of a vector with a for loop C++
body: <p>Currently doing an introduction course to c++, need to use a loop to read values from file to a vector, print that to console. This I've been able to do but, then I need to use a for-loop to find the average. I may be reading other code that I've looked at for clues... But can't seem to find much help.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  
  int main() {
  
      ifstream numbers;
      numbers.open("G:\\numbers.dat"); // just a file of 10 integers.
      int i;
      vector&lt;float&gt; vectors;
  
      while(numbers &gt;&gt; i) {
          vectors.push_back(i);
      }
  
      for(int n=0; n &lt; vectors.size(); ++n ){
          cout &lt;&lt; vectors[n] &lt;&lt; endl;
      }
  
      int avg;
      for(int k=0; k &lt; vectors.size(); ++k){
          // not sure what to put here basically.
          cout &lt;&lt; avg &lt;&lt; endl;
      }
  
  
      numbers.close();
  
      return 0;
  }
  </code></pre>
  
  <p>any help much appreciated. Thanks.</p>