Posted by: bange April 21, 2011
IT -- Solutions Center[Forum]
Login in to Rate this Post:     0       ?        
Namaste nepali8, good to see you are doing on your own (hope this is not copied).  As Ayus said, and you've realized too,
its not good to hard code the values. Try something like below on the above section.

                int count = 0;
while(! inputFile.eof())                   // i just count it all the value from the file.
{
if(inputFile >> number)
                        {
cout << number << endl;
                                count ++;       
                         }
else
break;
sum +=number;
average = sum/i;
                     
}
inputFile.close();
  }
        cout<<"Count is "<<count<<endl;
cout <<"Sum is" <<sum <<endl;
cout <<"average is" << average << endl;

Read Full Discussion Thread for this article