i am not getting it

0 girish gogia · June 23, 2015
I am not getting this if statement properly .

 this is the link to the tutorial:

if(ppg > bestPPG){
            bestPPG = ppg;
            bestPlayer = player;

^^ this is what i am having problem with.

Post a Reply


Oldest  Newest  Rating
0 girish gogia · June 26, 2015
thank you
0 Kenneth Malicay · June 25, 2015
int player[5] = {58,66,68,71,87};
int bestPlayer;
float ppg[5] = {0.87,1.3,0.89,0.97,1.19};
float bestPPG = 0.0;

for(i = 0; i < 5; i++) {
if(ppg[i] > bestPPG) {
// if ppg[i] is greater than bestPPG replace bestPPG value by ppg[i]
bestPPG = ppg[i];
// since ppg[i] and player[i] is on the same index,
// if ppg[i] is the best then player[i] is the best too,
// so set player[i] as bestPlayer
bestPlayer = player[i];

I removed the other codes and just hardcoded the ppg.
This is the simplest it could get so if you still don't get this I don't know how else I could help you.
0 girish gogia · June 25, 2015
bestPPG = ppg;
bestPlayer = player; 

what does this mean?
0 Kenneth Malicay · June 24, 2015
it means every loop it checks whether the player's PPG is greater than the current bestPPG and if yes then it would overwrite the current bestPPG and select the bestPlayer as the current player on the loop and it would loop again to check the next player and check it again and again as long as there are players left.



best points per game = 0

First loop
  points per game = goals / games played
  since first player's points per game is 0.87 then
  set best points per game = 0.87

Second loop
  ppg = goals / gamesPlayed
  since second player's ppg is 1.3 then
  set bestPPG = 1.3

Third loop
  ppg = goals / gamesPlayed
  since third player's ppg is 0.89
  it would not go inside the loop because ppg is 0.89 which is less than bestPPG which is 1.3.

and so on...

0 c student · June 24, 2015
Look around the forum.  There have already been answers for this.
  • 1



One of the most popular languages of all time.

Bucky Roberts Administrator