Help!!! trouble with Array loading and Debugging

I'm having some issues with this project I've got a baseline of code but my void is reading as incomplete. I'm thinking that it might have to do with the loading function. I have attached the project premise... I'llfigure out the comments and what not after I get the initial parts working....HELP!

Instructions:
Your college baseball team is rated number one in the state and the coach would like to keep it that way. After discovering that you know how to program, the coach has asked that you write a program to generate some important statistics about the players. With this information, the coach hopes to spot and improve any of the player's weak areas and thus keep the team's top ranking.
The coach wants you to store all the player information in an input file with the following data:
Player Number At Bats Hits Runs RBIs
10 36 25 2 5
2 12 5 0 1
34 18 7 1 0
63 41 20 4 2
12 10 3 1 0
14 2 1 1 1
27 55 27 10 8
8 27 12 3 4
42 32 8 2 1
33 19 4 1 0
Requirements:
1. Use an input file containing the defined data
2. Store all input information in parallel arrays.
3. The following arrays will be needed in your program:
a. Int playerNum[SIZE],
b. atBats[SIZE],
c. hits[SIZE],
d. runs[SIZE],
e. rbis[SIZE],
f. batAvg[SIZE];
g. where size is a defined constant with a value of 20.
4. Create the following functions
a. loadArrays - Reads the input data into the arrays. You do not know how many lines of input there will be, so you will need an EOF loop, and you will need to keep a count of the number of players stored.
2
b. batAvg - Calculates each player's batting average storing the results in the batAvg array. Batting average is computed by dividing hits by at bats. This will result in a percent, multiply the result by 1000 and round to the nearest integer to get the integer batting average.
c. printStats – Print a neatly formatted table with headings and one output line for each player containing player number, at bats, hits, runs RBIs, batting average and a comment about the player. Use the following scale to determine the comment:
Bat AvgComment
500-1000 WORLD SERIES
300-499 FARM LEAGUE
0-299 LITTLE LEAGUE
5. Use functions as you see fit to:
a. Calculate and output the total at bats, hits, runs, and rbis, and the team's batting average. Figure the team's batting average by dividing the total hits by the total at bats then multiplying by 1000 and rounding as previously described.
b. Output the best and worst values (and which player achieved them) for batting average, hits, and runs.
6. Functions must pass parameters and return values as needed.


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

#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;

//functions...
int loadArrays(int [], int [], int [], int [], int [], int);
int batAvg(int[], int[], int);
void printStats(int [], int [], int [], int [], int [],int[], int);



int main(int argc, const char * argv[]) {
   
    const int SIZE = 20;
    int playerNum[SIZE], atBats[SIZE], hits[SIZE], runs[SIZE], rbis[SIZE], batsAvg[SIZE], numberOfPlayers, count = 0;
   
    
    /*Reads the input data into the arrays. You do not know how many lines of input there will be, so you will need an EOF loop, and you will need to keep a count of the number of players stored.*/
    
    numberOfPlayers = loadArrays(playerNum, atBats, hits, runs, rbis, count);
    
   /*Calculates each player's batting average storing the results in the batAvg array. Batting average is computed by dividing hits by at bats. This will result in a percent, multiply the result by 1000 and round to the nearest integer to get the integer batting average.*/

    
    batsAvg[SIZE] = batAvg(hits,atBats,numberOfPlayers);
    

    void printStats(playerNum, atBats, hits, runs, rbis, batsAvg, numberOfPlayers);
   
    
    
    
    
    return 0;
}

int loadArrays(int player[], int bat[], int hit[], int run[], int rbi[], int count)
{
    ifstream statsIn;
    statsIn.open("info.txt");
    if (statsIn.fail())
        // this will alert user if there is a problem opening the file
        cout << "Error opening the file\n";
    while(!statsIn.eof())
    {
        statsIn >> bat[count];
        statsIn >> hit[count];
        statsIn >> run[count];
        statsIn >> rbi[count];
        count++;
    }
    statsIn.close();
    return count;
}

//calculate batting average
int batAvg(int hits[], int bats[],int count){
      int calcAVG = 0;
    
    for (int i=0; i<= count; i++) {
      
         calcAVG = (hits[i] / bats[i]) * 1000;
    }
        return calcAVG;

}
//display stats
void printStats(int player[], int bat[], int hit[], int run[], int rbi[],int bavg[],int count){

    cout<<"Player Num"<<"\t"<<"At Bat"<<"\t"<<"Hits"<<"\t"<<"Runs"<<"\t"<<"Bat Avg"<< endl;
    
    for (int i = 0; i <= count; i++) {
         cout<<player[i]<<"\t"<<bat[i]<<"\t"<<hit[i]<<"\t"<<run[i]<<"\t"<<rbi[i]<<"\t"<<bavg[i]<<endl;
    }
   
}
Topic archived. No new replies allowed.