troubleshooting Question

Getting the % of several numbers and make them add up to 100%

Avatar of Wanting2LearnMan
Wanting2LearnManFlag for United Kingdom of Great Britain and Northern Ireland asked on
C#Editors IDEs
7 Comments1 Solution325 ViewsLast Modified:
There are a certain number of kickouts in a soccer game.
The kickouts can be won like so
1. By heading the ball
2. Or by taking it down with your feet/chest
Now The above can be done by either team.
So lets say there are 4 possibilities on how the kickout can be won:
Team 1 - Heading the Ball
Team 1 - Feet/Chest
Team 2 - Heading the Ball
Team 2 - Feet/Chest
If there are 20 kickouts then the breakdown could be as follows:
Team 1 - 3/20 by Heading it
Team 1 - 6/20 by Using feet/chest
Team 2 - 5/20 by Heading it
Team 2 - 6/20 by Using feet/chest

I need to get 3/20, 6/20, 5/20 and 6/20 as a %.  I am doing the following:

double dPercentage = ((double)nNumber1 / (double)nNumber2) * 100;
dRoundedDownPercentage = Math.Floor(dPercentage);

This method always rounds the numbers down so the resulting %s will not all add up to 100%.  If I round up the %s then when I add up all the %s they come to shightly more than 100%.

How can I do this so the four %s add up exactly to 100%.

Thanks

Harry

               
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 7 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros