I'm trying to find the min/max of the number of years played and the min/max batting average of a list of players in an input file inputted in by the user that looks like this, the file is read and checked and then the program goes and gets the name, team, average, bats, hits.
Name Team Years at bats hits
Bob Astros 2 145 40
Sam Mets 1 100 35
Earl Giants 8 560 150
Joe Yankees 6 430 100
Mike Padres 3 265 95
John Twins 5 333 90
Frank Cardinals 7 450 80
Carl Athletics 4 300 105
Dev c++ is currently stuck on the very first if stmt and i'm not sure why.
Is there anything else you see wrong!!!! Please help not compiling!!!
It would be really appreciated!!!
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
ifstream infile;
int bats, hits, years;
string userfilename, name, team, minName, minimumYears, minTeam, minBats,
minHits, maximumYears, //declaring each item needed
maxName, maxTeam, maxBats, maxHits, maximumAvg, minimumAvg;
double average;
average = (hits/bats); //computing the average
minimumYears = 100000;
maximumYears = -1;
maximumAvg = -1; //initializing the Avg/Years
minimumAvg = 2;
cout <<"Enter the name of the input file: \n"; //User inputs file
cin >> userfilename;
infile.open(userfilename.c_str());
if(infile.fail())
{
cout << "Error opening file\n"; //check to see if file
exit(1); //opens correctly
}
cout <<"-------------------------------------------------------\n";
cout << "Name" << "Team" << "Average" << "At Bats" << "Hits" << endl;
cout <<"-------------------------------------------------------\n";
infile >> name >> team >> years >> bats >> hits;//file gets items
cout << name << team << average << bats << hits << endl;
infile >> name >> team >> years >> bats >> hits;
while(!infile.eof()) //until end of file do the following
{
if (years < minimumYears ) //find the minimumYears played
{
minimumYears = years;
minName = name;
minTeam = team;
minBats = bats;
minHits = hits;
}
if ( years > maximumYears ) //find maximumYears played
{
maximumYears = years;
maxName = name;
maxTeam = team;
maxBats = bats;
maxHits = hits;
}
//Going get another line of players info
infile >> name >> team >> years >> bats >> hits;
if ( average > maximumAvg)
{
maximumAvg = average;
maxName = name;
maxTeam = team;
maxBats = bats;
maxHits = hits;
}
if (average < minimumAvg)
{
minimumAvg = average;
minName = name;
minTeam = team;
minBats = Bats;
minHits = hits;
infile >> name >> team >> years >> bats >> hits;
}
cout << "Highest and Lowest Averages" << endl;
//print out info for the player with the maximumAvg
cout << maxName << maxTeam << maximumAvg << maxBats << maxHits << endl;
cout << minName << minTeam << minimumAvg << minBats << minHits << endl;
cout << "Most and Least Number of Years Played" << endl;
//Print out infor for max/min years played
cout << maxName << maxTeam << maximumYears << maxAvg << maxBats << maxHits << endl;
cout << minName << minTeam << minimumYears << minAvg << minBats << minHits << endl;
system("pause");
return 0;
}