/*This will calculate each player's batting average and store the results in
the batAvg array. The batting average is computed by dividing hits
by a player's at bats. This will result in a percent and then multiply the result
by 1000 and round to the nearest integer to get the integer
batting average.*/
int loadArrays(int player[], int bat[], int hit[], int run[], int rbi[])
{
int count = 0;
ifstream statsIn;
statsIn.open("baseballStats.txt");
if (statsIn.fail()) {
// This alerts the user if there is a problem opening the file.
cout << "Error opening the file\n";
return 0;
}
while (statsIn >> player[count]
>> bat[count]
>> hit[count]
>> run[count]
>> rbi[count]) {
count++;
}
statsIn.close();
return count;
}
//This is where the batting average is calculated.
void calcBatAvg(int hits[], int bats[], int batAvg[], int count) {
for (int i = 0; i< count; i++) {
batAvg[i] = (hits[i] * 1000 / bats[i]);
}
}
//These are the numbers that the Coach is looking for to include the batting average.
void printStats(int player[], int bat[], int hit[], int run[], int rbi[], int batAvg[], int count)
{