rendered paste body#include <iostream>
#include <fstream>
#include <string>
using namespace std;
float getpart(ifstream& myfile);
#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.ignore(5, '\n');
}
myfile.close();
}
return 0;
}
float getpart(ifstream& myfile)
{
int x = 0;
int y = 0;
float pct;
float indices = 0;
myfile >> x;
while (x != BADINPUT)
{
myfile >> y;
pct = x/y;
cout << x << " " << y << endl;
cout << pct << endl;
indices++;
myfile >> x;
}
return pct / indices;
}