#include <iostream>
using namespace std;

// a struct created to store one int, plus the link
struct Score
{
  int value;
  Score* next; // the link
};
 
int main()
{
  // create an empty linked list
  Score* start = 0;
 
  // read and save the records
  while (true)
  {
    // Step 1, create a node 
    Score* aScore = new Score;

    // Step 2, read its int value
    cout << "Enter a score [-1 to quit]: ";
    cin >> aScore->value;
    cin.ignore(1000, 10);

    // before linking it in, check for sentinel value
    if (aScore->value == -1) break;

    // Step 3, add node to list
    aScore->next = start;
    start = aScore;
  } 
 
  // traverse the list and get the average
  int count = 0; // to count the number of nodes in the list
  int sum = 0; // to accumulate the total of all scores
  Score* p;
  for (p = start; p; p = p->next)
  {
    sum += p->value;
    count++;
  }

  // output the result
  if (count > 0)
  {
    float average = (float)sum / count;
    cout << "The average of " << count << " scores is " << average << endl;
  }
  else
    cout << "No values were entered.\n";
}
