I dont know what is wrong. The output didnt show anythin. FYI I have p6.dat on same dic. it just the out put didnt print the number.
#include <iostream>
#include <fstream>
using namespace std;
const int mySize = 15;
const int myStop = 3;
void impliedTask(int *&,float *&);
int main ()
{
int *myFile = new int[mySize];
float *avg = new float[mySize/myStop];
ifstream project;
project.open("p6.dat");
if (!project)
{
cout << "error" << endl;
}
int num = 0;
while (!project.eof()) //read file to end of file
{
project >> myFile[num];
++ num;
}
for (int i = 0; i < 15; i++)
{
cout << myFile [i] << endl;
}
impliedTask(myFile,avg);
delete []avg;
delete []myFile;
project.close ();
return 0;
}
void impliedTask(int *&myFile,float *&avg)
{
int sum=0;
cout<<"===Start==="<<endl;
for(int i=0,j=0;i<mySize;i++)
{
cout<<endl;
cout<<"Number @index["<<i<<"] is: "<<myFile[i]<<endl;
sum+=myFile[i];//accumulate sum
cout<<"Sum @index["<<i<<"] is: "<<sum<<endl;
if(j>=myStop-1)//stop to make adjust if j counter >=2 (0,1,2) == 3 numbers
{
avg[i/myStop] = float(sum)/float(myStop);//insert avg into index i/3
cout<<"Average index["<<i/myStop<<"] is: "<<float(int(10*avg[i/myStop]))/10<<endl;
j=sum=0;//reset j counter and sum
}
else
{
j++;
}
}
}