How to calculate the stats of a player by looking through their recent goals and number of games they played !!
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <math.h>
int main()
{
int i;
int player [5] = {58,66,68,71,87};
int goals [5] = {26,39,25,29,31};
int gamesPlayed [5] = {30,30,28,30,26};
float ppg [5];
float bestppg = 0.0;
int bestplayer;
for(i=0;i<5;i++){
ppg[i] = (float)goals[i] / (float)gamesPlayed[i];
printf("%d \t%d\t%d\t%.2f \n",player[i],goals[i],gamesPlayed[i],ppg[i]);
if(ppg[i] > bestppg){
bestppg = ppg[i];
bestplayer = player[i];
}
}
printf("\nThe best player is %d",bestplayer);
return 0;
}
Comments
Post a Comment