heimsventus

untitled

Mar 7th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. // ConsoleApplication2.cpp : Defines the entry point for the console application.
  2. //
  3. #include<fstream>
  4. #include<iostream>
  5. #include<string>
  6. #include<cstdlib>
  7. #include<ctime>
  8. #include "stdafx.h"
  9.  
  10. using namespace std;
  11.  
  12. int main()
  13. {
  14.     ifstream fin("rainfall.txt");
  15.     double number = 0.0, sum = 0.0, average = 0.0;
  16.     int count = 0;
  17.  
  18.     do
  19.     {
  20.         fin >> number;
  21.         sum = sum + number;
  22.         count++;
  23.        
  24.  
  25.     } while (number != -999);
  26.  
  27.     average = sum / count;
  28.    
  29.     cout << "The average is " << average << endl;
  30.     system("pause");
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment