1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65

#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
void calculations (double &min, double &max, double &average);
void results (double min, double max, double average);
int main()
{
double min, max, average;
calculations (min, max, average);
results (min, max, average);
std::cin.ignore();
std::cin.get();
return 0;
}
void calculations (double &min, double &max, double &average)
{
int counter=0;
double number,
sum=0,
average,
maximum = 99999,
minimum = 99999;
ifstream inFile;
inFile.open("numbers.txt");
if(inFile.fail())
{
cout << "File could not be opened.";
exit(1);
}
while (inFile>>number)
{
if (number>max)
{
max=number;
}
if (number<min)
{
min=number;
}
sum=sum+number;
counter++;
}
average=sum/counter;
inFile.close();
}
void results (double min, double max, double average)
{
cout << "The minimum is: " << setprecision(2) << min << endl;
cout << "The maximum is: " << setprecision(2) << max << endl;
cout << "The average is: " << setprecision(2) << average << endl;
}
 