Suppose a file has a sequence of integers:1 2 3 4 5 6
The following is the code. It should read all the integers and output averages of 4 integers until the file ends.
The output should be
2.5 ((1+2+3+4)/4)
3.5 ((2+3+4+5)/4)
4.5 ((3+4+5+6)/4)
I just can't get the logic in the while loop.Code:string filename; ifstream fin; cin>>filename; fin.open(filename.data()); int w,x,y,z,temp; fin>>w>>x>>y>>z; fin>>temp; while (!fin.eof()) { w=x; x=y; y=z; z=temp; cout<<(w+x+y+z)/4; fin>>temp; } fin.close(); }
If w=x, why is the first integer not skipped?