Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fstream help

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
The file avg.dat contains the info:
5
33
44
55
66
77
3
49
86
75
2
33
44


This means that after the first line in the file, 5, the next 5 numbers will be averaged....how do i do this?>
 
#include<iostream>
#include<fstream>
using namespace std;

int main()
{
ifstream x(&quot;xx.txt&quot;);
int count=0;
int sum=0;
double avg;
while(x)
{
x>>count;
for(int i=0;i<count;i++)
{
int y=0;
x>>y;
sum+=y;
}
avg=(double)sum/(double)count;
sum=0;
cout<<&quot;avg=&quot;<<avg<<endl;
}
return 0;
} John Fill
1c.bmp


ivfmd@mail.md
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top