# Calculating Hit Accuracy score in a game

I'm currently in the process of making a scoreboard for my game. One of things I would like to display is the players accuracy in the amount of hits they had in game. However, I have never done this before and I've no idea how to go about doing this.

Is there a commonly used algorithm out there that can help me calculate this, or has someone found a way to calculate this fairly easily?

Any help with this would be appreciated.

• ShotsHit / ShotsFired * 100? Or did I mis-understand the question..?
– user9790
Commented Dec 6, 2012 at 9:33
• @JaakkoLipsanen Nah I think that's just it, you should post this as answer. Commented Dec 6, 2012 at 9:43
• The 'algorithm' is just the addition of one to the accuracy variable, executed on every hit, i.e. accuracy++;. Commented Dec 6, 2012 at 12:16
• -1 If you have to ask how to calculate a percentage, you've definitely not done enough research.
– Anko
Commented Dec 6, 2012 at 21:35

float hitAccuracy = ShotsHit / ShotsFired * 100;

• Depending on the type of ShotsFired and ShotsHit you might want to cast them first to avoid integer division. Also I don't consider the number of shots fired being an issue. Such games usually show both values and only consider values for rankings, if a given minimum number of shots have been fired. One more thing to note, which might be more serious issue: If you're able to hit multiple targets, it's possible to get more than 100% (or back to 100%) rather easy (prominent example: Battlefield 3's shotguns). Commented Dec 6, 2012 at 11:07
• @Mario: Why? If you hit two targets with one shot, ShotsHit would be incremented by one, or the variable ought to be renamed TargetsHit. Commented Dec 6, 2012 at 12:11