I have this code for the task mentioned in the title:
The program reads from a 1 columned text file in which the numbers are below each other.
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
double number;
double sum = 0;
ifstream average;
average.open("average.txt");
while (average >> number)
{
for(int i = 0; i < 10; i++)
{
sum = sum + number;
i++;
if (i = 9)
{
cout << sum / 10 << endl;
}
}
{
average.close();
system("pause");
return 0;
}
But somehow it doesn't average the numbers just divide all of them by 10.
What might be the problem?
Thanks