/*
The following program reads the name of an input file that has the 
following contents: The first line contains information about 
the contents of the file. Every other line contains a SSN of a student 
of the format AAA-BB-CCCC followed by a grade of type float for that 
student. Write a program to find the average of the grades in the file.
 */
#include <iostream>
#include <string>
#include <fstream>
using namespace std;

int main()
{
	ifstream inFile;
	string fileName, line, SSN;
	float grade, avg = 0;
	int count = 0;
	cout << "Enter the name of the file: ";
	cin >> fileName;
	inFile.open(fileName.c_str());
	if (!inFile)
	{
		cout << "can't open the file." << endl;
		return 1;
	}
	getline(inFile,line);
	inFile >> SSN >> grade;
	while (inFile)
	{
		count++;
		avg += grade;
		inFile >> SSN >> grade;
	}
	if (count != 0)
	{
		cout << "The average of the grades in the file is: "
			<< avg / count << "." << endl;
	}
	else
		cout << "There are no grades in the file. " << endl;
	return 0;
}

