### 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!

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243`` ``````#include 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().

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

 ``353637`` ``````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:
 ``65666768`` ``````void Player::setData(float FTA, float FTM, float FGA, float FGM) { calcFTP(); calcFGP(); }``````

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

 ``12345678`` ``````void Player::setData(float fta, float ftm, float fga, float fgm) { FTA = fta; FTM = ftm; FGA = fga; FGM = fgm; calcFTP(); calcFGP(); }``````