when i run my program it runs with no erorrs but the output screen is giving me strange results
here is whats its giving me:
CONFERENCE OVERALL
RANK TEAM W-L % WINS MARGIN W-L % WINS MARGIN
KSU 3-1 0.75 10.5 8-1 1.#IO 1.#J
CAP 3-1 0.75 11.75 7-2 1.#IO 1.#J
HEID 1-3 0.25 -4.00 3-4 1.#IO 1.#J
JCU 0-3 0.00 -9.75 2-5 1.#IO -1.#J
MAR 0-4 0.00 -29.75 2-7 1.#IO -1.#J
MUC 2-2 0.50 -6.25 4-4 1.#IO -1.#J
MUSK 1-2 0.25 -9.00 5-3 1.#IO 1.#J
ONU 3-1 0.75 15.25 7-2 1.#IO 1.#J
OTT 3-1 0.75 14.00 5-4 1.#IO 1.#J
WILM 3-1 0.75 7.25 7-2 1.#IO 1.
here is what its supposed to look like:
CONFERENCE OVERALL
RANK TEAM W-L % WINS MARGIN W-L % WINS MARGIN
1 KSU 3-1 .750 +10.50 8-1 .889 +13.56
1 CAP 3-1 .750 +11.75 7-2 .778 +13.67
1 ONU 3-1 .750 +15.25 7-2 .778 +17.78
1 OTT 3-1 .750 +14.00 5-4 .556 +7.56
1 WILM 3-1 .750 +7.25 7-2 .778 +10.00
6 MUC 2-2 .500 -6.25 4-4 .500 -0.50
7 MUSK 1-2 .333 -12.00 5-3 .625 +2.63
8 HEID 1-3 .250 -4.00 3-4 .429 +1.57
9 JCU 0-3 .000 -13.00 2-5 .286 -3.00
9 MAR 0-4 .000 -29.75 2-7 .222 -10.89
here is my code how should i fix to make it stop giving me those strange things:
here is whats its giving me:
CONFERENCE OVERALL
RANK TEAM W-L % WINS MARGIN W-L % WINS MARGIN
KSU 3-1 0.75 10.5 8-1 1.#IO 1.#J
CAP 3-1 0.75 11.75 7-2 1.#IO 1.#J
HEID 1-3 0.25 -4.00 3-4 1.#IO 1.#J
JCU 0-3 0.00 -9.75 2-5 1.#IO -1.#J
MAR 0-4 0.00 -29.75 2-7 1.#IO -1.#J
MUC 2-2 0.50 -6.25 4-4 1.#IO -1.#J
MUSK 1-2 0.25 -9.00 5-3 1.#IO 1.#J
ONU 3-1 0.75 15.25 7-2 1.#IO 1.#J
OTT 3-1 0.75 14.00 5-4 1.#IO 1.#J
WILM 3-1 0.75 7.25 7-2 1.#IO 1.
here is what its supposed to look like:
CONFERENCE OVERALL
RANK TEAM W-L % WINS MARGIN W-L % WINS MARGIN
1 KSU 3-1 .750 +10.50 8-1 .889 +13.56
1 CAP 3-1 .750 +11.75 7-2 .778 +13.67
1 ONU 3-1 .750 +15.25 7-2 .778 +17.78
1 OTT 3-1 .750 +14.00 5-4 .556 +7.56
1 WILM 3-1 .750 +7.25 7-2 .778 +10.00
6 MUC 2-2 .500 -6.25 4-4 .500 -0.50
7 MUSK 1-2 .333 -12.00 5-3 .625 +2.63
8 HEID 1-3 .250 -4.00 3-4 .429 +1.57
9 JCU 0-3 .000 -13.00 2-5 .286 -3.00
9 MAR 0-4 .000 -29.75 2-7 .222 -10.89
here is my code how should i fix to make it stop giving me those strange things:
Code:
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <fstream>
using namespace std;
struct basketballStat
{
string schoolName;
int numberWins;
int numberLosses;
int numberPointsTheTeamScored;
int numberPointsTheTeamScoredAgainst;
int teamOverallWins;
int teamOverallLosses;
int numberPointsTheTeamScoredInAll;
int numberPointsTheTeamScoredInAllAgainst;
int rank;
};
struct basketballStatUpdate
{
string date;
string nameOfHomeTeam;
int homeTeamsPointTotal;
string nameOfVisitTeam;
int VisitingTeamsPointTotal;
};
void FormerStats (ifstream&, basketballStat&);
void Updates (ifstream&, basketballStatUpdate&);
void DoUpdate(basketballStat[], basketballStatUpdate&);
void UpdatedStats(ostream&, basketballStat[]);
void Standings(ostream&, basketballStat[]);
int main ()
{
basketballStat formerStats[10];
ifstream inFile1;
inFile1.open ("G:\\formerstats.txt");
ifstream inFile2;
inFile2.open("G:\\updates.txt");
ofstream outFile1;
outFile1.open ("G:\\updatedStats.txt");
ofstream outFile2;
outFile2.open ("G:\\standings.txt");
for (int k=0; k<10; k++)
{
FormerStats (inFile1, formerStats[k]);
}
while (!inFile2.eof())
{
basketballStatUpdate update;
Updates (inFile2, update);
DoUpdate(formerStats, update);
}
inFile1.close();
inFile2.close();
UpdatedStats(outFile1, formerStats);
outFile2<<setw(30)<<"CONFERENCE"<<setw(10)<<"OVERALL"<<endl;
outFile2<<"RANK"<<setw(6)<<"TEAM"<<setw(7)<<"W-L"<<setw(9)<<"% WINS"<<setw(11)<<"MARGIN"<<setw(8)<<"W-L"<<setw(9)<<"% WINS"<<setw(11)<< "MARGIN"<<endl;
Standings(outFile2, formerStats);
return 0;
}
void FormerStats (ifstream &inFile1, basketballStat &myStat) //this void function reads in the data from formerstats
//within the basketballStat struct.
{
inFile1 >> myStat.schoolName;
inFile1 >> myStat.numberWins;
inFile1 >> myStat.numberLosses;
inFile1 >> myStat.numberPointsTheTeamScored;
inFile1 >> myStat.numberPointsTheTeamScoredAgainst;
inFile1 >> myStat.teamOverallWins;
inFile1 >> myStat.teamOverallLosses;
inFile1 >> myStat.numberPointsTheTeamScoredInAll;
inFile1 >> myStat.numberPointsTheTeamScoredInAllAgainst;
}
void Updates (ifstream& inFile2, basketballStatUpdate &update) //this void function reads in the data from updates.txt and
//struct called basketballStat update is being used to read in the data.
{
inFile2 >> update.date;
inFile2 >> update.nameOfHomeTeam;
inFile2 >> update.homeTeamsPointTotal;
inFile2 >> update.nameOfVisitTeam;
inFile2 >> update.VisitingTeamsPointTotal;
}
void DoUpdate(basketballStat myStat[], basketballStatUpdate &update) // this function updates the stats of the conference games
// and calculates each data for each game and updates it into a recent and update form of the stats in the conference games.
{
bool homeOfTheConfTeam = false, visitConfTeam = false;
int homeTeamIndex, visitTeamIndex;
for (int j=0; j<10; j++)
{
if (myStat[j].schoolName==update.nameOfHomeTeam)
{
homeOfTheConfTeam = true;
homeTeamIndex = j;
} else if (myStat[j].schoolName==update.nameOfVisitTeam)
{
visitConfTeam = true;
visitTeamIndex = j;
}
if (homeOfTheConfTeam&&visitConfTeam) break;
}
bool homeWin = (update.homeTeamsPointTotal > update.VisitingTeamsPointTotal);
if (homeOfTheConfTeam)
{
myStat[homeTeamIndex].numberPointsTheTeamScoredInAll += update.homeTeamsPointTotal;
myStat[homeTeamIndex].numberPointsTheTeamScoredInAllAgainst += update.VisitingTeamsPointTotal;
if (homeWin)
myStat[homeTeamIndex].teamOverallWins++;
else
myStat[homeTeamIndex].teamOverallLosses++;
}
if (visitConfTeam)
{
myStat[visitTeamIndex].numberPointsTheTeamScoredInAll += update.VisitingTeamsPointTotal;
myStat[visitTeamIndex].numberPointsTheTeamScoredInAllAgainst += update.homeTeamsPointTotal;
if (!homeWin)
myStat[visitTeamIndex].teamOverallWins++;
else
myStat[visitTeamIndex].teamOverallLosses++;
}
if (homeOfTheConfTeam&&visitConfTeam)
{
myStat[homeTeamIndex].numberPointsTheTeamScored += update.homeTeamsPointTotal;
myStat[homeTeamIndex].numberPointsTheTeamScoredAgainst += update.VisitingTeamsPointTotal;
myStat[visitTeamIndex].numberPointsTheTeamScored += update.VisitingTeamsPointTotal;
myStat[visitTeamIndex].numberPointsTheTeamScoredAgainst += update.homeTeamsPointTotal;
if (homeWin)
{
myStat[homeTeamIndex].numberWins++;
myStat[visitTeamIndex].numberLosses++;
} else
{
myStat[visitTeamIndex].numberWins++;
myStat[homeTeamIndex].numberLosses++;
}
}
}
void UpdatedStats(ostream &outFile1, basketballStat myStats[])// this function stores the calculations from the upbove function
// and uses a set of arrays to write the updated stats data in the outfile1.
{
for (int m=0; m<10; m++)
{
outFile1 << myStats[m].schoolName << " ";
outFile1 << myStats[m].numberWins << " ";
outFile1 << myStats[m].numberLosses << " ";
outFile1 << myStats[m].numberPointsTheTeamScored << " ";
outFile1 << myStats[m].numberPointsTheTeamScoredAgainst << " ";
outFile1 << myStats[m].teamOverallWins << " ";
outFile1 << myStats[m].teamOverallLosses << " ";
outFile1 << myStats[m].numberPointsTheTeamScoredInAll << " ";
outFile1 << myStats[m].numberPointsTheTeamScoredInAllAgainst << " " << endl;
}
}
void Standings(ostream &outFile2, basketballStat myStats[])
{
float total=4.0;
//float answer=9;
for(int j=0; j<10; j++)
{
//outFile2<<myStats[j].rank<<endl;
outFile2<<setw(14)<<myStats[j].schoolName;
outFile2<<setw(10)<<myStats[j].numberWins<<'-';
outFile2<<myStats[j].numberLosses;
outFile2<<setw(8)<<myStats[j].numberWins/total;
outFile2<< setw(13)<<(myStats[j].numberPointsTheTeamScored-myStats[j].numberPointsTheTeamScoredAgainst)/total<<" ";
outFile2<<setw(12)<<myStats[j].teamOverallWins<<'-';
outFile2<<myStats[j].teamOverallLosses;
float numberGamesTotalPlayed=0;
if(numberGamesTotalPlayed<=10)
{
outFile2<<setw(8)<<fixed<<setprecision(3)<<myStats[j].teamOverallWins/numberGamesTotalPlayed;
outFile2<<setw(8)<<fixed<<setprecision(2)<<(myStats[j].numberPointsTheTeamScoredInAll-myStats[j].numberPointsTheTeamScoredInAllAgainst)/numberGamesTotalPlayed<<endl;
}
}
}