#include #include #include using namespace std; int main() { float x; unsigned short num_scores, icnt; ifstream infile; // Declare infile as as input file stream object float sum = 0.0; infile.open( "data.dat" ); // Open data.dat /// and connect it to infile if ( infile.fail() ) { // Check to see if connection was made 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 << endl; 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 ); }