codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  ******I NEED HELP ASAP**********************  CIK at 02:32 on Wednesday, May 02, 2007
 

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








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
//








Recent Forum Threads
•  string break up
•  help me how to execute a linux shell script file(.sh file ) in perl
•  C++ help!!! pls..about cards..
•  Re: need help!!!
•  ******I NEED HELP ASAP**********************
•  Problem in Java to launch ExamXML on Linux
•  Re: dynamic crystal report generation
•  Writing form data to output files
•  date of birth validation using java script-very urgent


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2007