I need my program to read a list of numbers from and input file, random.txt, and calculate the following statistics on those numbers:
A. The number of numbers in the file.
B. The sum of all the numbers in the file.
C. The average of all the numbers in the file.
D. The largest number in the file.
E. The smallest number in the file.
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
usingnamespace std;
int main()
{
int totalNumbers = 0;
int sum = 0;
int avg = 0;
ifstream inputFile;
int number;
inputFile.open("random.txt");
if (!inputFile)
{
cout << "Error opening file." << endl;
}
else
{
while (inputFile >> number)
{
cout << number << endl;
}
inputFile.close();
}
while (inputFile.good())
{
inputFile >> number;
++totalNumbers;
sum += number;
}
avg = sum / totalNumbers;
cout << "Number of numbers is: " << totalNumbers << endl;
cout << "The sum of the numbers is: " << sum << endl;
cout << "The average of the numbers is: " << avg << endl;
return 0;
}