| kobrakai5687 (1) | |
|
I have a code and i am using arrays and it is mostly completed. What im doing is getting the average of 8 players on their hits walks and outs, but i need to figure out how to get the full team average. As well as getting it started at 1 instead of 0. Any help is greatly appreciated thanks. #include <iostream> #include <conio.h> using namespace std; const int MAX=8; // Chapter 11 introduction struct player_type { int hits; int walks; int outs; player_type() // constructor { hits=0; walks=0; outs=0; } //---------------------------------------------- float avg() { if(hits+outs) return (float)hits/(hits+outs); else return -1.0; } //------------------------------------------------- void print() { cout<<"\nhits\twalks\touts\taverage\n" <<hits<<'\t'<<walks<<'\t'<<outs <<'\t'<<avg()<<'\n'; } }; int main() { int h, w, o, p; player_type team[MAX]; // Now I have eight!!! cout<<"Enter player's number: "; cin>>p; while(p>=0) { cout<<"Enter the hits, walks, and outs:\n"; cin>>h>>w>>o; if (p<MAX&&p>=0) { team[p].hits += h; team[p].walks=team[p].walks+w; team[p].outs=team[p].outs+o; } else cout<<"ERROR!\n"; cout<<"Enter the player's number: \n"; cin>>p; } for(int i=0; i<MAX; i++) team[i].print(); cout << "\n\nTerminating\n"; getch(); return 0; } | |
|
Last edited on
|
|