// I am trying to figure out how to sum up each 5 rows of numbers // then divide
ID: 3623728 • Letter: #
Question
// I am trying to figure out how to sum up each 5 rows of numbers// then divide by 5 to get the average, then get the average for the next
// 5 numbers in the other row!! am I doing something wrong or something,
// cause I come up with the wrong answers
#include <iostream>
#include <cmath>
#include <iomanip>
#include <fstream>
using namespace std;
int main()
{
double sum;
double number;
int count;
ifstream indata;
indata.open("numbers.txt");
indata >> number;
while (indata)
{
sum = 0;
count = 1;
while(count <= 5)
{
sum = sum + number;
count++;
indata >> number;
}
cout << sum/count << endl;
indata >> number;
}
indata.close();
system("PAUSE");
return 0;
}