All pastes #253752 Raw Edit

Mine

public text v1 · immutable
#253752 ·published 2006-11-21 01:48 UTC
rendered paste body
#include <iostream>
#include <fstream>
#include <string>


using namespace std;

float getpart(ifstream& myfile);

int x = 0;
int y = 0;

#define BADINPUT -1

int main()
{
	ifstream myfile;
	string filename;

	cout << "Your Grade Calculator!" << endl;
	cout << "What file has your scores in it?: ";
	cin >> filename;
	cout << endl;

	myfile.open(filename.c_str());

	if (!myfile)
	{
		cout << "The file could not be opened." << endl;
		return 0;
	}
	else
	{
		for(int i = 0; i < 5; i++)
		{
			string label;
			getline(myfile, label);
			float runit = getpart(myfile);
			cout << label << "  " << (runit * 100) << endl;
		}

		myfile.close();
	}
	return 0;
}




float getpart(ifstream& myfile)
{  
	float pct = 0;
	float indices = 0;

	myfile >> x;
	myfile >> y;

	while (x != BADINPUT)
	{
		pct += (x / y);
		indices++;
		myfile >> x;
		myfile >> y;
	}

	return pct / indices;
}