Soultion Of Class A

posted May 13, 2013, 12:56 PM by Salah Ibrahim   [ updated May 13, 2013, 12:56 PM by Karwan Jacksi ]
#include <iostream>
#include <fstream>
using namespace std;

double average(double sum,int count)
{
return sum/count;
}

void main()
{
int num;
double sum = 0;
int count = 0;
ofstream ofile;
ofile.open("result.txt");
for(i=0; i<20; i++)
{
cout<<"Enter number ("<<i<<") : ";
cin>>num;
if(num >= 0)         
                {
 count += 1;      
 sum += num;    
        }
}
cout<<"Sum : "<<sum<<endl;
ofile<<"Sum : "<<sum<<endl;
cout<<"Average : "<<average(sum, count)<<endl;
ofile<<"Average : "<<average(sum, count)<<endl;
ofile.close();
system("pause");
}
Comments