I'm not looking for a direct answer or anything considering I'm doing this for homework, but I'm a little confused on why my batting average and slugging percentage do not work.
batAvg = singles + doubles + triples + homeRuns / atBats;
slgPer = singles + 2* doubles + 3* triples + 4* homeRuns / atBats;
cout << "Name AB 1B 2B 3B HR avg slg" << endl;
cout << "------------------ --- --- --- --- --- ------ ------" << endl;
cout << setw(18) << left << plrName
<< setw(6) << right << atBats
<< setw(4) << singles
<< setw(4) << doubles
<< setw(4) << triples
<< setw(4) << homeRuns
<< setw(7) << batAvg
<< setw(7) << slgPer
<< endl;
return 0;
}
It outputs it completely wrong...
Name AB 1B 2B 3B HR avg slg
------------------ --- --- --- --- --- ------ ------
Jeremy 600 520 40 10 10 570 1
What can I do to get a real average or slugging percentage?