1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
#include <iostream>
#include <fstream>
#include <iomanip>
#define FILE_IN "packers.dat"
using namespace std;
struct playerinfo
{
string playernum, playername, playerpos, playercol;
int height, weight, age, exp;
}team [53];
void findaverages (int, playerinfo[], float*, float*);
void writeplayerdata (int, playerinfo[], float, float);
int main()
{
char junk, exit;
float avheight, avweight;
int teamsize = 53, counter;
cout << "This is the 2013-2014 Green Bay Packers team roster:";
cout << endl;
cout << endl;
ifstream input;
input.open (FILE_IN, ios::in);
if (!input)
{
cout<<"Error accessing packers.dat";
return 1;
}
else
{
for (counter = 0; counter < 53; counter ++)
{
input >> team[counter].playernum;
input.get (junk);
input >> team[counter].playername;
input.get (junk);
input >> team[counter].playerpos;
input.get (junk);
input >> team[counter].height;
input.get (junk);
input >> team[counter].weight;
input.get (junk);
input >> team[counter].age;
input.get (junk);
input >> team[counter].exp;
input.get (junk);
input >> team[counter].playercol;
input.get (junk);
}
}
input.close();
findaverages (teamsize, team, &avheight, &avweight); //no flaw here, this works
writeplayerdata (teamsize, team, avheight, avweight); //This may be the problem, so I'll include this function
cout << "f";
cout << endl;
cout << "Press Enter to end the program. ";
cin >> exit;
}
void writeplayerdata (int teamsize, playerinfo team[], float avgheight, float avgweight)
{
int teamcounter;
for (teamcounter = 0; teamcounter < teamsize; ++teamcounter)
{
cout << setw(3) << team[teamcounter].playernum << setw(10);
cout << team[teamcounter].playername << setw(6);
cout << team[teamcounter].playerpos << setw(5);
cout << team[teamcounter].height << setw(6);
cout << team[teamcounter].weight << setw(5) << team[teamcounter].age;
cout << setw(4) << team[teamcounter].playercol << setw(5);
cout << team[teamcounter].exp;
cout << endl;
cout << endl;
}
cout << "The average height of the team is " << avgheight << "inches.";
cout << endl;
cout << "The average weight of the team is " << avgweight << "pounds.";
}
|