#include #include #include using namespace std; int main() { float x, sum = 0.0; unsigned short num_scores, icnt; ifstream infile( "data.dat" ); // Declare and open data.dat // and connect it to infile // Check to see if connection was made if ( infile.fail() ) { cout << "** The file data.dat could not be opened **\n"; system( "PAUSE" ); exit( EXIT_FAILURE ); } cout << "Enter the number of scores in file data.dat\n"; cin >> num_scores; cout << "\n"; for ( icnt = 1; icnt <= num_scores; icnt++ ) { infile >> x; sum += x; } cout << "The average of the scores is " << sum / float( num_scores ); cout << "\n\n"; system( "PAUSE" ); return( EXIT_SUCCESS ); }