# Dividing stats in C

This is a discussion on Dividing stats in C within the C Programming forums, part of the General Programming Boards category; I'm trying to create a statistic showing a percentage by dividing two other statistics, but the code I've tried doesn't ...

1. ## Dividing stats in C

I'm trying to create a statistic showing a percentage by dividing two other statistics, but the code I've tried doesn't seem to work. The relevant code is below. The line giving me the problem is player->hits_to_miss=((*player)).number_hits/(player->total_shots)*100:
Code:
```void update_stats (Stats *player, Boolean hit_status)
{
if (hit_status == TRUE)
{
((*player).number_hits)++;
}
else
{
(player->number_misses)++;
}
(player->total_shots)++;
player->hits_to_miss=((*player)).number_hits/(player->total_shots)*100;
}
void print_stats (Stats player)
{
printf ("Hits: %d, Misses: %d, Total Shots: %d, Accuracy: %.1lf percent\n", player.number_hits, player.number_misses, player.total_shots, player.hits_to_miss);
}```
I've tried various iterations such as
Code:
`	player->hits_to_miss=(player->number_hits/(player->total_shots)*100`
Code:
`	player->hits_to_miss=((*player).number_hits/((*player).total_shots)*100`
, but basically I'm shooting in the dark. Is there a way to do this?

2. but the code I've tried doesn't seem to work.
Hmmmm

3. Dividing ints will get you integer results. Check your line again with that in mind.

but basically I'm shooting in the dark
Pun intended?

4. Originally Posted by bernt
Dividing ints will get you integer results. Check your line again with that in mind.

Pun intended?
/facepalm

Durr. Sorry, it's been a few months since I wrote code.

5. Thanks, bernt! That hint was exactly what I needed. Converted the integer values to double values, and now the program works like a champ!