I am trying to compute a percentage that calculates the number of home team wins but keep receiving 0 when I know the values I am dividing by are correct.
I've tried calculating it with values that are pointers and then have the percentage outputted by a pointer, but nothing seems to work.
//update function
void update(int * totalGames, int * homeTeamWins, double * homeTeamWinPercentage, int difference) {
*totalGames = *totalGames + 1;
if (difference >= 0)
*homeTeamWins = *homeTeamWins + 1;
homeTeamWinPercentage = (*homeTeamWins / *totalGames);
}
//summary function
void summary(int totalGames, int homeTeamWins, double homeTeamWinPercentage) {
//* homeTeamWinPercentage = (homeTeamWins / totalGames);
printf("\n Of the %d total games, %d home teams won, resulting in a %d%.2f%% home team win percentage\n", totalGames, homeTeamWins, homeTeamWinPercentage);
}
// in my main
void main() {
...
...
while (!feof(file1)) {
output(homeTeam, visitingTeam, difference);
update(&totalGames, &homeTeamWins, &homeTeamWinPercentage, difference);
}
summary(totalGames, homeTeamWins, homeTeamWinPercentage);
system("pause");
}
Of the 13 total games, 7 home teams won, resulting in a -8589934600.00% home team win percentage.
I can tell it is pointing to somewhere in memory. I have gotten it to print 0.00% for the percentage but that still does not help me.
I am trying to acheive homeTeamWins / totalGames = homeTeamWinPercentage (7/13=53.18%) but am having trouble.