Function call issues

PROBLEM SOLVED!

This is a homework assignment that relates to march madness basketball stats. I haven't finished all of the details yet but here is the basis of the question:

In the spirit of the NBA All Star Game, we will write a program that enables the user to enter a basketball player’s name and his following raw statistics: free throws attempted (FTA), free throws made (FTM), field goals attempted (FGA), field goals made (FGM), rebounds (R), assists (A), steals (S), blocked shots (B) and games played (G). Based on these raw statistics, calculate the following finished statistics for the player: free throw percentage, field goal percentage, points per game, rebounds per game, assists per game, steals per game, and blocked shots per game. The two shooting percentages are computed by dividing shots made by shots attempted and multiplying by 100. The per game averages are computed by dividing the raw statistic by games played. For the case of points per game, a field goal counts two points and a free throw as one point. All figures should be displayed with one digit to the right of the decimal point.


For some reason my function calls are acting up in my get member functions when I call them in main. Also, when I do my setData function, it doesn't like it one bit and I think it has something to do with the variables its getting. Help/explanation of solution appreciated! Thanks!


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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#include <iostream>
using namespace std;


class Player {
private:
	void calcFTP(void);
	void calcFGP(void);
public:
	float FTA, FTM, FGA, FGM, FTP, FGP, PPG, RPG, APG, SPG, BPG;
	float R, A, S, B, G;
	void dataCheck(void);
	void setFTA(void);
	void setFTM(void);
	void setFGA(void);
	void setFGM(void);
	void setR(void);
	void setA(void);
	void setS(void);
	void setB(void);
	void setG(void);
	void getPPG(void) {cout << "Average points per game--> " << PPG << endl;}
	void getRPG(void) {cout << "Average rebounds per game--> " << RPG << endl;}
	void getAPG(void) {cout << "Average assists per game--> " << APG << endl;}
	void getSPG(void) {cout << "Average steals per game--> " << SPG << endl;}
	void getBPG(void) {cout << "Average blocks per game--> " << BPG << endl;}
	void getFTP(void) {cout << "Average free throw percentage--> " << FTP << "%" << endl;}
	void getFGP(void) {cout << "Average field goal percentage--> " << FGP << "%" << endl;}
	void setData(float FTA, float FTM, float FGA, float FGM);
	void calcPPG(void);
	void calcRPG(void);
	void calcAPG(void);
	void calcSPG(void);
	void calcBPG(void);
	
	
	
};

	void Player::calcPPG(void) {

		PPG = ((FTM+(FGM*2))/G);
	}

	void Player::calcRPG(void) {
		
		RPG = (R/G);
	}

	void Player::calcAPG(void) {

		APG = (A/G);
	}

	void Player::calcSPG(void) {

		SPG = (S/G);
	}

	void Player::calcBPG(void) {

		BPG = (B/G);
	}

	void Player::setData(float FTA, float FTM, float FGA, float FGM) {
		calcFTP();
		calcFGP();

	}

	void Player::calcFTP(void) {
		FTP = (FTM/FTA ) * 100;

	}

	void Player::calcFGP(void) {
		FGP = (FGM/FGA) * 100;
	}

	void Player::setFTA(void) {
		
		cout << "Please enter the player's number of free throws attempted: ";
		cin >> FTA;

			while(FTA < 0) {
		cout << "Invalid data entry." << endl;
		cout << "Please enter a positive value." << endl << endl;
		cout << "Please reenter the player's number of free throws attempted: ";
		cin >> FTA;
		
	}
}

	void Player::setFTM(void) {
		
		cout << "Please enter the player's number of free throws made: ";
		cin >> FTM;

			while(FTM < 0) {
		cout << "Invalid data entry." << endl;
		cout << "Please enter a positive value." << endl << endl;
		cout << "Please reenter the player's number of free throws made: ";
		cin >> FTM;
		
	}
}

	void Player::setFGA(void) {
		
		cout << "Please enter the player's number of field goals attempted: ";
		cin >> FGA;

			while(FGA < 0) {
		cout << "Invalid data entry." << endl;
		cout << "Please enter a positive value." << endl << endl;
		cout << "Please reenter the player's number of field goals attempted: ";
		cin >> FGA;
		
	}
}

	void Player::setFGM(void) {
		
		cout << "Please enter the player's number of field goals made: ";
		cin >> FGM;

			while(FGM < 0) {
		cout << "Invalid data entry." << endl;
		cout << "Please enter a positive value." << endl << endl;
		cout << "Please reenter the player's number of field goals made: ";
		cin >> FGM;
		
	}
}

	void Player::setR(void) {
		
		cout << "Please enter the player's number of rebounds: ";
		cin >> R;

			while(R < 0) {
		cout << "Invalid data entry." << endl;
		cout << "Please enter a positive value." << endl << endl;
		cout << "Please reenter the player's number of rebounds: ";
		cin >> R;
		
	}
}

	void Player::setA(void) {
		
		cout << "Please enter the player's number of assists: ";
		cin >> A;

			while(A < 0) {
		cout << "Invalid data entry." << endl;
		cout << "Please enter a positive value." << endl << endl;
		cout << "Please reenter the player's number of assists: ";
		cin >> A;
		
	}
}
	void Player::setS(void) {
		
		cout << "Please enter the player's number of steals: ";
		cin >> S;

			while(S < 0) {
		cout << "Invalid data entry." << endl;
		cout << "Please enter a positive value." << endl << endl;
		cout << "Please reenter the player's number of steals: ";
		cin >> S;
		
	}
}

	void Player::setB(void) {
		
		cout << "Please enter the player's number of blocked shots: ";
		cin >> B;

			while(B < 0) {
		cout << "Invalid data entry." << endl;
		cout << "Please enter a positive value." << endl << endl;
		cout << "Please reenter the player's number of blocked shots: ";
		cin >> B;
		
	}
}
	void Player::setG(void) {
		
		cout << "Please enter the player's number of games played: ";
		cin >> G;

			while(G < 0) {
		cout << "Invalid data entry." << endl;
		cout << "Please enter a positive value." << endl << endl;
		cout << "Please reenter the player's number of games played: ";
		cin >> G;
		
	}
}



int main(void)
{


	

	Player Patrick;

	Patrick.setFTA();
	Patrick.setFTM();
	Patrick.setFGA();
	Patrick.setFGM();
	Patrick.setR();
	Patrick.setA();
	Patrick.setS();
	Patrick.setB();
	Patrick.setG();
	

	Patrick.calcPPG();
	Patrick.calcRPG();
	Patrick.calcAPG();
	Patrick.calcSPG();
	Patrick.calcBPG();
	Patrick.setData(FTA,FTM,FGA,FGM); // Says they are undefined? Pass by reference maybe?
	Patrick.getFTP();
	Patrick.getFGP();
	Patrick.getPPG();
	Patrick.getRPG();
	Patrick.getAPG();
	Patrick.getSPG();
	Patrick.getBPG();
	

	return 0;
}

Last edited on
> For some reason my function calls are acting up in my get member functions when I call them in main.
¿what?
Patrick.getPPG(); ¿what's that supposed to do? ¿line 22 or line 35?

By the way
> In the 1979–80 season, the NBA adopted the three-point shot
Patrick.getPPG(); is supposed to call the average points per game member function. Also, our professor said to use 2 points per shot only for now.
ne555's point was that you have two conflicting implementions of getPPG().

22
23
void getPPG(void) 
{cout << "Average points per game--> " << PPG << endl;}


35
36
37
void Player::getPPG(void) 
{  PPG = ((FTM+(FGM*2))/G);
}

If you call patrick.getPPG(), which one will be executed?



Ahh ok. I changed void Player::getPPG(void) into a new member function called calcPPG.. It also seems that I did that with a lot of the other ones lol.

Alright I went through and touched up some of the smaller issues, but my setData function call is saying that the variables in it are undefined. Do I have to pass them by reference?

I edited my original post with all of my new additions.


Actually I just fixed my problems! YAY
Last edited on
Your setData function doesn't store anything:
65
66
67
68
void Player::setData(float FTA, float FTM, float FGA, float FGM) 
{  calcFTP();
    calcFGP();
}

You pass the variables, but don't assign them to anything.

Try this instead:
1
2
3
4
5
6
7
8
void Player::setData(float fta, float ftm, float fga, float fgm) 
{  FTA = fta;
    FTM = ftm;
    FGA = fga; 
    FGM = fgm;
    calcFTP();
    calcFGP();
}

Note. I've changed the capitialization of the arguments so the names don't conflict with the member variables.


Last edited on
Topic archived. No new replies allowed.