the idea of the program is to take in an amount of baseball players with their at bats and hits values for 1 game. In the end it needs to total up the values and come up with a team batting average. Now when indivually calculating the average values for each player, there is no error, but when the team average needs to be calculated the answer always comes to 1.000. Where did i go wrong?
CODE
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
int main()
{
string name,team,posi;
int j;
double avg,atbats,hits,teamavg,teamatbats,teamhits;
const int LOOP_LIMIT=3;
cout<<setiosflags(ios::fixed|ios::showpoint)<<setprecision(3);
cout<<"Enter the team name"<<endl;
getline(cin, team);
for(j=1;j<=LOOP_LIMIT; ++j)
{
cout<<"Enter the player name"<<endl;
getline(cin, name);
cout<<"Enter the position played"<<endl;
getline(cin, posi);
cout<<"Enter the player's at bats:"<<endl;
cin>>atbats;
cout<<"Enter the player's hits:"<<endl;
cin>>hits;
cout<<endl;
cout<<name<<endl;
avg=(hits/atbats);
cout<<avg<<endl;
cout<<endl;
cout<<"Player # "<<j<<endl;
cin.ignore();
}
cout<<team<<endl;
cout<<endl;
teamatbats=(teamatbats+atbats);
teamhits=(teamhits+hits);
teamavg=(teamhits/teamatbats);
cout<<"The team's batting average is: "<<teamavg<<endl;
return 0;
}
*edit: In the future use code tags. Please and thank you.
This post has been edited by Martyr2: 6 Dec, 2007 - 12:32 PM