Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Voting Booth does't add up

by eak (Monk)
on Aug 12, 2000 at 08:22 UTC ( #27607=monkdiscuss: print w/replies, xml ) Need Help??

I was in the voting booth today and I noticed that the percentages for the 90 votes only added up to 96%. If we have a voting booth, shouldn't the %'s = 100? I took this as a challenge to write a better voting booth rounder.
--eric
#!/usr/bin/perl -w use strict; my %votes = ( plane => 5, cbn => 10, wall => 2, pass => 11, shirt => 5, vison => 7, mind => 26, name => 10, tooth => 14, ); my $total; for (values %votes){ $total += $_; } my %pcts; my $diff = 100; foreach my $vote (keys %votes){ my $pct = $votes{$vote}/$total * 100; $diff -= int($pct); $pcts{$vote} = $pct; } my $format = "%-12s" x 3; my @titles = qw(ANSWER VOTES/PCT RAW-PCT); printf("$format\n", @titles); my $new_total = 0; foreach my $answ (sort { ($pcts{$b} - int($pcts{$b})) <=> ($pcts{$a} - int($pcts{$a})) } keys %pcts ){ my $round = int($pcts{$answ}); $round += 1 if $diff-- > 0; printf("$format\n",$answ,"$votes{$answ}/$round%", $pcts{$answ}); $new_total += $round; } print "\n\tNew % Total: $new_total%\n";

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: monkdiscuss [id://27607]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2022-01-21 21:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (59 votes). Check out past polls.

    Notices?