So I have a program with a specification file, implementation file, and a client file, I'll post all three but I know the problem rests in the client file. What's happening is that it reads the first team from my data file which I'll also post, and then it doesn't output the other two teams correctly. Anyway here's all the stuff:
// Implementation file for Team ADT.
#include <iostream>
#include "team.h"
#include <string>
using namespace std;
void TeamClass::Set(string teamname)
{
teamName = teamname;
wins = 0;
losses = 0;
GameCount = 0;
totalteamscore = 0;
totalotherscore = 0;
return;
}
void TeamClass::AddGame(int teamscore, int otherscore)
{
team = teamscore;
other = otherscore;
if (teamscore > otherscore)
{
wins = wins + 1;
GameCount = GameCount + 1;
totalteamscore = totalteamscore + teamscore;
totalotherscore = totalotherscore + other;
}
else
{
losses = losses + 1;
GameCount = GameCount + 1;
totalteamscore = totalteamscore + teamscore;
totalotherscore = totalotherscore + other;
}
}
string TeamClass::GetName()
{
cout << teamName <<endl;
}
int TeamClass::GetWins()
{
cout << "Wins: " << wins <<endl;
}
int TeamClass::GetLosses()
{
cout << "Losses: " << losses <<endl;
}
float TeamClass::GetWinPct()
{
WinPct = wins/GameCount;
cout <<"Pct: " << WinPct << endl;
}
int TeamClass::GetScoreDiff()
{
ScoreDiff = totalteamscore - totalotherscore;
cout << "Differential: " << ScoreDiff << endl;
}
// Specification file <team.h> for tracking teams.
#include <string>
using namespace std;
class TeamClass
{
public:
void Set(string);
void AddGame(int, int);
string GetName();
int GetWins();
int GetLosses();
float GetWinPct();
int GetScoreDiff();
private:
string teamName;
int team;
int other;
int wins;
int losses;
float WinPct;
int ScoreDiff;
float GameCount;
int totalteamscore;
int totalotherscore;
};
#include "team.h"
#include <string>
#include <fstream>
using namespace std;
int main()
{
TeamClass aTeam;
string teamName;
int team;
int other;
ifstream inFile;
string filename;
cout << "Input file?" << endl;
cin >> filename;
inFile.open(filename.c_str());
getline(inFile, teamName);
while (inFile)
{
aTeam.Set(teamName);
inFile >> team >> other;
while (team!=-1 && other != -1)
{
aTeam.AddGame(team, other);
inFile >> team >> other;
}
aTeam.GetName();
aTeam.GetWins();
aTeam.GetLosses();
aTeam.GetWinPct();
aTeam.GetScoreDiff();
}
return 0;
}
And the text file reads as is:
St. John's Purple Dragons
2 0
0 1
4 1
-1 -1
General McLane Lancers
4 1
0 1
5 2
-1 -1
Raging Rhinos
3 2
1 0
-1 -1
I would appreciate any help on the matter, like I said I've pinpointed it to the Client File, but I can't figure out what's wrong with it.