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";

In reply to Voting Booth does't add up by eak

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.