Ashieboy
Member level 1
Code:
#include <iostream>
#include <fstream>
using namespace std;
int main(){
string line;
float x,sum=0,average,b;
int y=0,i,j,k=0;
float n1[1000];
float n2[1000];
ifstream myfile("sensor.txt");
if(myfile.is_open())
{
getline(myfile,line);
while(myfile.good())
{
myfile>>x;
n1[y]=x;
y=y+1;
}myfile.close();
for(i=0;i<y;i++)
{
sum=sum+n1[i];
}
average=sum/y;
cout<<"The sum of the number is "<<sum<<endl;
cout<<"The average is "<<average<<endl;
cout<<"\nThe number larger than average"<<endl;
for(i=0;i<y;i++)
{
b=n1[i];
if(b>average)
{
cout<<n1[i]<<endl;
}
else
{
continue;
}
}
}
else{cout<<"\nunable to open";}
}