C++ functions and where to go next in the program

hi, having trouble figuring out how to get the comments to go to the comment area of the program, tried an if statement but it just doesn't work for me, any advice or direction i appreciate. this is the directions for the program.

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 importantstatistics 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 stored all the player information in an input file named “BaseballStats.txt” containing the
following data:
Player Num 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 input file BaseballStats.txt
2. Store all input data in the following parallel arrays:
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.
3. Create the following functions
a. void loadArrays (int[], int[], int[], int[], int[], int[], int &);
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.
b. void calcBatAvg (int[], int[], int[], int);
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. void printStats(int[], int[], int[], int[], int[], int[], int);
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
4. 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.
5. Functions must pass parameters and return values as needed, using local variables and not accessing
global variables..


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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
  #include <iostream>
#include <string>
#include <iomanip>
#include <fstream>

using namespace std;


int load2Arrays(int[], int[], int[], int[], int[]);
void calBatAvg(int[], int[], int[], int);
void printStats(int[], int[], int[], int[], int[], int[], int);


int main()
{

	const int SIZE = 20;
	int playerNum[SIZE];
	int atBats[SIZE];
	int hits[SIZE];
	int runs[SIZE];
	int rbis[SIZE];
	int batAvg[SIZE];
	int numberOfPlayers;


	cout << fixed << showpoint << setprecision(2);
	


	numberOfPlayers = load2Arrays(playerNum, atBats, hits, runs, rbis);

	calBatAvg(hits, atBats, batAvg, numberOfPlayers);

	printStats(playerNum, atBats, hits, runs, rbis, batAvg, numberOfPlayers);

	if (batAvg > 500)











	system("pause");
	return 0;


}

int load2Arrays(int playernum[], int atbats[], int hits[], int runs[], int rbis[])
{
	//open file
	ifstream inputFile;
	inputFile.open("balltats.txt");

	int count = 0;

	while (inputFile >> playernum[count] 
		>> atbats[count] 
		>> hits[count] 
		>> runs[count] 
		>> rbis[count])
		count++;

	return count;
		
		inputFile.close();

}




void calBatAvg(int hits[], int bats[], int batAvg[], int count)
{
	for (int x = 0; x < count; x++)
	{
		batAvg[x] = (hits[x] * 1000 / bats[x]);
	}


	

}


void printStats(int player[], int bats[], int hits[], int runs[],
	int rbis[], int batAvg[], int count)
{
	cout << "Player Number" << "\t" << "At Bats" << "\t" << "Hits"
		<< "\t" << "Runs" << "\t" <<"RBI's" <<"\t"<< "Batting Avg." <<"\t" << "Comment" <<endl;

	for (int y = 0; y < count; y++)
	{

		cout <<"\t" << right << player[y] << "\t" << bats[y] << "\t" << hits[y] << "\t" <<
			runs[y] << "\t" << rbis[y] << "\t" << batAvg[y] << endl;
	}
	
}
the comments are pre-generated ...
I think you need to do some logic in the printstats:

before the end of line in print stats, end the first print statement and then do something like:

if(batAvg[y] > 500)
cout << "World Series" << endl;
else
if(... etc

you don't store the comments, you just generate them based off the average.
Last edited on
Topic archived. No new replies allowed.