#include <fstream> 
#include <iostream> 
using namespace std; 
  
const int SIZE = 8; // global: visible to all functions and main 
  
void readScores(int* score) 
{ 
  ifstream fin; 
  fin.open("8Scores.txt"); 
  if (!fin.good()) throw "I/O error"; 
  
  // read and save the scores
  for (int i = 0; i < SIZE; i++) 
  { 
    fin >> score[i]; // read directly into the array
    fin.ignore(1000, 10); 
  } // for 
  fin.close(); 
} // readScores 
  
double getAverage(int* score) 
{ 
  double result = 0;

  // find the average 
  int scoreTotal = 0; 
  for (int i = 0; i < SIZE; i++) 
    scoreTotal += score[i]; 
  result = (double)scoreTotal / SIZE;
 
  return result; 
} // getAverage 
  

int countScoresGreater(int* score, double x) 
{ 
  int result = 0;
  for (int i = 0; i < SIZE; i++) 
    if (score[i] > x) result++; 
  return result; 
} // countScoresGreater 
  
int main() 
{ 
  int score[SIZE]; 
  readScores(score); 
  double average = getAverage(score) ; 
  cout << "The average of " << SIZE 
    << " numbers is " << average << endl; 
  cout << countScoresGreater(score, average) 
    << " scores are greater than the average." << endl; 
} // main 
