// 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;
}
Explanation / Answer
Dear, Here is the code #include #include using namespace std; void main() { //Start main function int count,num,sum; //Variable declaration ifstream infile; infile.open("fileName.txt"); infile>>num; //Logic while(infile) { sum=0; count=0; while(count>num; } coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.