Hey guys, I need some help with my C++ final. I'm trying to write a program that will store and edit statistics. Here it is.
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
int main ()
{
int edit;
int wins;
int games;
int player;
int hits;
int at_bats;
int team_avg;
int MuellerAvg, OrtizAvg, RamirezAvg, DamonAvg, MillarAvg, VaritekAvg, BellhornAvg, ReeseAvg, KaplerAvg, CrespoAvg, BurksAvg, McCartyAvg, DaubachAvg, MirabelliAvg;
ofstream team;
ofstream BMueller;
ofstream DOrtiz;
ofstream MRamirez;
ofstream JDamon;
ofstream KMillar;
ofstream JVaritek;
ofstream MBellhorn;
ofstream PReese;
ofstream GKapler;
ofstream CCrespo;
ofstream EBurks;
ofstream DMcCarty;
ofstream BDaubach;
ofstream DMirabelli;
cout << "What will you be editing in your baseball teams statistics today?\n";
cout << "(1) Edit Team Win/Loss Record\n";
cout << "(2) View Team Win/Loss Record\n";
cout << "(3) Edit Individual Batting Averages\n";
cout << "(4) View Individual Batting Averages\n";
cin >> edit;
switch(edit)
{
case 1:
ofstream team;
cout << "Input the number of new wins since the last time you used this program.\n";
cin >> wins;
cout << "Input the number of new games since the last time you used this program.\n";
cin >> games;
team.open("TEAM.DAT",ios::out);
if(team)
{
team << wins<< endl;
team << games<< endl;
team.close();
}
else
{
cout << "Error. Please contact developer.\n";
}
break;
case 2:
{
ifstream team;
team.open("TEAM.DAT",ios::in);
if(team)
{
do
{ team >> wins;
team >> games;
team_avg = wins/games;
cout.setf(ios::fixed);
cout << "The RedSox win average is " <<setprecision(3) << team_avg << endl;
}
while(games !=0);
case 3:
cout << "Which players statistics do you wish to edit?\n";
cout << "(1) B Mueller\n";
cout << "(2) D Ortiz\n";
cout << "(3) M Ramirez\n";
cout << "(4) J Damon\n";
cout << "(5) K Millar\n";
cout << "(6) J Varietk\n";
cout << "(7) M Bellhorn\n";
cout << "(8) P Reese\n";
cout << "(9) G Kapler\n";
cout << "(10) C Crespo\n";
cout << "(11) E Burks\n";
cout << "(12) D McCarty\n";
cout << "(13) B Daubach\n";
cout << "(14) D Mirabelli\n";
cin >> player;
switch(player)
{
case 1:
ofstream BMueller;
cout << "Input the number of hits for B Mueller now.\n";
cin >> hits;
cout << "Input the number of at-bats for B Mueller now.\n";
cin >> at_bats;
BMueller.open("BMUELLER.DAT",ios::out);
if(BMueller)
{
BMueller << hits << endl;
BMueller << at_bats << endl;
BMueller.close();
}
else
{
cout << "Error. Please contact the developer.\n";
}
break;
case 2:
ofstream DOrtiz;
cout << "Input the number of hits for D Ortiz now.\n";
cin >> hits;
cout << "Input the number of at-bats for D Ortiz now.\n";
cin >> at_bats;
DOrtiz.open("DORTIZ.DAT",ios::out);
if(DOrtiz)
{
DOrtiz << hits << endl;
DOrtiz << at_bats << endl;
DOrtiz.close();
}
else
{
cout << "Error. Please contact the developer.\n";
}
break;
case 3:
ofstream MRamirez;
cout << "Input the number of hits for M Ramirez now.\n";
cin >> hits;
cout << "Input the number of at-bats for M Ramirez now.\n";
cin >> at_bats;
MRamirez.open("MRamirez.DAT",ios::out);
if(MRamirez)
{
MRamirez << hits << endl;
MRamirez << at_bats << endl;
MRamirez.close();
}
else
{
cout << "Error. Please contact the developer.\n";
}
break;
case 4:
ofstream JDamon;
cout << "Input the number of hits for J Damon now.\n";
cin >> hits;
cout << "Input the number of at-bats for J Damon now.\n";
cin >> at_bats;
JDamon.open("JDAMON.DAT",ios::out);
if(JDamon)
{
JDamon << hits << endl;
JDamon << at_bats << endl;
JDamon.close();
}
else
{
cout << "Error. Please contact the developer.\n";
}
break;
case 5:
ofstream KMillar;
cout << "Input the number of hits for K Millar now.\n";
cin >> hits;
cout << "Input the number of at-bats for K Millar now.\n";
cin >> at_bats;
KMillar.open("KMILLAR.DAT",ios::out);
if(KMillar)
{
KMillar << hits << endl;
KMillar << at_bats << endl;
KMillar.close();
}
else
{
cout << "Error. Please contact the developer.\n";
}
break;
case 6:
ofstream JVaritek;
cout << "Input the number of hits for J Varitek now.\n";
cin >> hits;
cout << "Input the number of at-bats for J Varitek now.\n";
cin >> at_bats;
JVaritek.open("JVARITEK.DAT",ios::out);
if(JVaritek)
{
JVaritek << hits << endl;
JVaritek << at_bats << endl;
JVaritek.close();
}
else
{
cout << "Error. Please contact the developer.\n";
}
break;
case 7:
ofstream MBellhorn;
cout << "Input the number of hits for M Bellhorn now.\n";
cin >> hits;
cout << "Input the number of at-bats for M Bellhorn now.\n";
cin >> at_bats;
MBellhorn.open("MBELLHORN.DAT",ios::out);
if(MBellhorn)
{
MBellhorn << hits << endl;
MBellhorn << at_bats << endl;
MBellhorn.close();
}
else
{
cout << "Error. Please contact the developer.\n";
}
break;
case 8:
ofstream PReese;
cout << "Input the number of hits for P Reese now.\n";
cin >> hits;
cout << "Input the number of at-bats for P Reese now.\n";
cin >> at_bats;
PReese.open("PREESE.DAT",ios::out);
if(PReese)
{
PReese << hits << endl;
PReese << at_bats << endl;
PReese.close();
}
else
{
cout << "Error. Please contact the developer.\n";
}
break;
case 9:
ofstream GKapler;
cout << "Input the number of hits for G Kapler now.\n";
cin >> hits;
cout << "Input the number of at-bats for G Kapler now.\n";
cin >> at_bats;
GKapler.open("GKAPLER.DAT",ios::out);
if(GKapler)
{
GKapler << hits << endl;
GKapler << at_bats << endl;
GKapler.close();
}
else
{
cout << "Error. Please contact the developer.\n";
}
break;
case 10:
ofsteam CCrespo;
cout << "Input the number of hits for C Crespo now.\n";
cin >> hits;
cout << "Input the number of at-bats for C Crespo now.\n";
cin >> at_bats;
CCrespo.open("CCRESPO.DAT",ios::out);
if(CCrespo)
{
CCrespo << hits << endl;
CCrespo << at_bats << endl;
CCrespo.close();
}
else
{
cout << "Error. Please contact the developer.\n";
}
break;
case 11:
ofstream EBurks;
cout << "Input the number of hits for E Burks now.\n";
cin >> hits;
cout << "Input the number of at-bats for E Burks now.\n";
cin >> at_bats;
EBurks.open("EBURKS.DAT",ios::out);
if(EBurks)
{
EBurks << hits << endl;
EBurks << at_bats << endl;
EBurks.close();
}
else
{
cout << "Error. Please contact the developer.\n";
}
break;
case 12:
ofstream DMcCarty
cout << "Input the number of hits for D McCarty now.\n";
cin >> hits;
cout << "Input the number of at-bats for D McCarty now.\n";
cin >> at_bats;
DMcCarty.open("DMCCARTY.DAT",ios::out);
if(DMcCarty)
{
DMcCarty << hits << endl;
DMcCarty << at_bats << endl;
DMcCarty.close();
}
else
{
cout << "Error. Please contact the developer.\n";
}
break;
case 13:
ofstream BDaubach
cout << "Input the number of hits for B Daubach now.\n";
cin >> hits;
cout << "Input the number of at-bats for B Daubach now.\n";
cin >> at_bats;
BDaubach.open("BDAUBACH.DAT",ios::out);
if(BDaubach)
{
BDaubach << hits << endl;
BDaubach << at_bats << endl;
BDaubach.close();
}
else
{
cout << "Error. Please contact the developer.\n";
}
break;
case 14:
ofstream DMirabelli;
cout << "Input the number of hits for D Mirabelli now.\n";
cin >> hits;
cout << "Input the number of at-bats for D Mirabelli now.\n";
cin >> at_bats;
DMirabelli.open("DMIRABELLI.DAT",ios::out);
if(DMirabelli)
{
DMirabelli << hits << endl;
DMirabelli << at_bats << endl;
DMirabelli.close();
}
else
{
cout << "Error. Please contact the developer.\n";
}
break;}
case 4:
cout << "Which players statistics do you wish to view?\n";
cout << "(1) B Mueller\n";
cout << "(2) D Ortiz\n";
cout << "(3) M Ramirez\n";
cout << "(4) J Damon\n";
cout << "(5) K Millar\n";
cout << "(6) J Varietk\n";
cout << "(7) M Bellhorn\n";
cout << "(8) P Reese\n";
cout << "(9) G Kapler\n";
cout << "(10) C Crespo\n";
cout << "(11) E Burks\n";
cout << "(12) D McCarty\n";
cout << "(13) B Daubach\n";
cout << "(14) D Mirabelli\n";
cin >> player;
switch(player)
case 1:
if (BMueller)
{
cout.setf(ios::fixed);
cout << "B Mueller's batting average is as follows:\n";
cout << setprecision(3);
do
{
BMueller << hits;
BMueller << at_bats;
MuellerAvg = hits/at_bats;
cout << MuellerAvg <<endl;
}
while(hits != 0);}
else
{
cout << "Error. Please contact the developer.\n";
}
if (DOrtiz)
{
cout.setf(ios::fixed);
cout << "D Ortiz's batting average is as follows:\n";
cout << setprecision(3);
do
{
DOrtiz << hits;
DOrtiz << at_bats;
OrtizAvg = hits/at_bats;
cout << OrtizAvg <<endl;
}
while(hits != 0);}
else
{
cout << "Error. Please contact the developer.\n";
}
if (MRamirez)
{
cout.setf(ios::fixed);
cout << "M Ramirez's batting average is as follows:\n";
cout << setprecision(3);
do
{
MRamirez << hits;
MRamirez << at_bats;
RamirezAvg = hits/at_bats;
cout << RamirezAvg <<endl;
}
while(hits != 0);}
else
{
cout << "Error. Please contact the developer.\n";
}
if (JDamon)
{
cout.setf(ios::fixed);
cout << "J Damon's batting average is as follows:\n";
cout << setprecision(3);
do
{
JDamon << hits;
JDamon << at_bats;
DamonAvg = hits/at_bats;
cout << DamonAvg <<endl;
}
while(hits != 0);}
else
{
cout << "Error. Please contact the developer.\n";
}
if (KMillar)
{
cout.setf(ios::fixed);
cout << "K Millar's batting average is as follows:\n";
cout << setprecision(3);
do
{
KMillar << hits;
KMillar << at_bats;
MillarAvg = hits/at_bats;
cout << MuellerAvg <<endl;
}
while(hits != 0);}
else
{
cout << "Error. Please contact the developer.\n";
}
if (JVaritek)
{
cout.setf(ios::fixed);
cout << "J Varitek's batting average is as follows:\n";
cout << setprecision(3);
do
{
JVaritek << hits;
JVaritek << at_bats;
VaritekAvg = hits/at_bats;
cout << MuellerAvg <<endl;
}
while(hits != 0);}
else
{
cout << "Error. Please contact the developer.\n";
}
if (MBellhorn)
{
cout.setf(ios::fixed);
cout << "M Bellhorn's batting average is as follows:\n";
cout << setprecision(3);
do
{
MBellhorn << hits;
MBellhorn << at_bats;
BellhornAvg = hits/at_bats;
cout << BellhornAvg <<endl;
}
while(hits != 0);}
else
{
cout << "Error. Please contact the developer.\n";
}
if (PReese)
{
cout.setf(ios::fixed);
cout << "P Reese's batting average is as follows:\n";
cout << setprecision(3);
do
{
PReese << hits;
PReese << at_bats;
ReeseAvg = hits/at_bats;
cout << ReeseAvg <<endl;
}
while(hits != 0);}
else
{
cout << "Error. Please contact the developer.\n";
}
if (GKapler)
{
cout.setf(ios::fixed);
cout << "G Kapler's batting average is as follows:\n";
cout << setprecision(3);
do
{
GKapler << hits;
GKapler << at_bats;
KaplerAvg = hits/at_bats;
cout << KaplerAvg <<endl;
}
while(hits != 0);}
else
{
cout << "Error. Please contact the developer.\n";
}
if (CCrespo)
{
cout.setf(ios::fixed);
cout << "C Crespo's batting average is as follows:\n";
cout << setprecision(3);
do
{
CCrespo << hits;
CCrespo << at_bats;
CrespoAvg = hits/at_bats;
cout << CrespoAvg <<endl;
}
while(hits != 0);}
else
{
cout << "Error. Please contact the developer.\n";
}
if (EBurks)
{
cout.setf(ios::fixed);
cout << "E Burks's batting average is as follows:\n";
cout << setprecision(3);
do
{
EBurks << hits;
EBurks << at_bats;
BurksAvg = hits/at_bats;
cout << BurksAvg <<endl;
}
while(hits != 0);}
else
{
cout << "Error. Please contact the developer.\n";
}
if (DMcCarty)
{
cout.setf(ios::fixed);
cout << "D McCarty's batting average is as follows:\n";
cout << setprecision(3);
do
{
DMcCarty << hits;
DMcCarty << at_bats;
McCartyAvg = hits/at_bats;
cout << McCartyAvg <<endl;
}
while(hits != 0);}
else
{
cout << "Error. Please contact the developer.\n";
}
if (BDaubach)
{
cout.setf(ios::fixed);
cout << "B Daubach's batting average is as follows:\n";
cout << setprecision(3);
do
{
BDaubach << hits;
BDaubach << at_bats;
DaubachAvg = hits/at_bats;
cout << DaubachAvg <<endl;
}
while(hits != 0);}
else
{
cout << "Error. Please contact the developer.\n";
}
if (DMirabelli)
{
cout.setf(ios::fixed);
cout << "D Mirabelli's batting average is as follows:\n";
cout << setprecision(3);
do
{
DMirabelli << hits;
DMirabelli << at_bats;
MirabelliAvg = hits/at_bats;
cout << MirabelliAvg <<endl;
}
while(hits != 0);}
else
{
cout << "Error. Please contact the developer.\n";
}
}
}
}
return 0;
}