/*
(10)	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 <fstream>
#include <string>
#include <iostream>
using namespace std;
int main()
{
	ifstream inFile;
	string inFileName, ssn, line;
	float grade, sum = 0;
	int count = 0;

	cout << "Enter the input file name: ";
	cin >> inFileName;

	inFile.open(inFileName.c_str());

	if (!inFile)
	{
		cout << "Can't open file " << inFileName << ".\n";
		return 1;
	}


	getline(inFile,line);
	inFile >> ssn >> grade;
	while (inFile)
	{
		sum += grade;
		count++;
		inFile >> ssn >> grade;
	}

	if (count > 0)
		cout << "Average = " << sum/count << endl;
	else
		cout << "No grades in file.\n";

	inFile.close();

	return 0;
}
