|
I HAVE AN ISSUE WITH MY CODE. IT DOES NOT WANT TO RUN. IT COMPILES WITH NO PROBLEM BUT WONT EXECUTE.
IT IS THE BASEBALL ARRAY PROBLEM I HAVE TO GRAB BATTING DATA FROM A FILE AND DISPLAY IT TO THE SCREEN.
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
const int numOnTeam = 20;
int main()
{
int hits[21];
int walks[21];
int outs[21];
int avg [21];
int playerID;
int playerHits;
int playerWalks;
int playerOuts;
int playerAvg;
int teamAvg;
int nth;
int numRecs = 0;
ifstream inFile;
cout << "Baseball Stats:\n\n"
<< "Player's IDs range from 1 through 20;\n"
<< " the statistics are in file players.txt\n ;"
<< " player ID, # OF HITS , # of walks, and # of outs;\n"
<< " where the numbers are separated by blanks.\n\n";
for ( nth = 0; nth <= numOnTeam; nth++)
{
hits[ nth ] = 0;
walks[ nth ] = 0;
outs[ nth ] = 0;
}
// open
inFile.open("a:\baseball");
if ( !inFile )
{
cout << "Can not load players.txt !\n ";
return (1);
}
// first player's statistics
inFile >> playerID >> playerHits >> playerWalks >> playerOuts>>playerAvg;
while ( inFile )
{
numRecs++;
// update player's statistics
hits[ playerID ] = hits[ playerID ] + playerHits;
walks[ playerID ] = walks[ playerID ] + playerWalks;
outs[ playerID ] = outs[ playerID ] + playerOuts;
avg[ playerID ] = avg[ playerID ] + playerAvg;
inFile >> playerID >> playerHits >> playerWalks >> playerOuts>>playerAvg;
}
inFile.close()
;
cout << "Player Hits Walks Outs Average \n ";
cout << "------ ------- ----- ----- ----------\n\n";
//
for ( nth = 1; nth <= numOnTeam; nth++)
//
if ( hits[ nth ] + outs[ nth ] == 0 )
cout << setprecision(3) << fixed
<< setw(4) << nth
<< setw(12) << "No at bats"
<< setw(7) << walks [ nth ] << endl;
else
cout << setprecision(3) << fixed
<< setw(4) << nth
<< setw(12) << float( hits[ nth ] ) /
float( hits[ nth ] + outs[ nth ] )
<< setw(7) << walks [ nth ] << endl;
//
cout << "\n\nNumber of player records read: "<< numRecs;
cout << "\n\nTeam average is : " << teamAvg;
cout << "\nEnd of Player statistics program.Copyright 2029\n\n";
return(0);
}
<Added>
THANK U AHEAD OF TIME!!!! IT SHOULD DISPLAY A TABLE WITH THE BASEBALL DATA BUT INSTEAD THE .EXE FILE DOSENT RUN....HELP PLEASE
|
|
|
|
|
|
|
// |