Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
#!/usr/bin/perl -w use strict; my (%pick, %rand) = (); my ($plays, $money, $years, $week, $win, $count) = 0; srand(); print "How many times do you play the lottery every week?\n"; chomp(my $wcheck = <>); $week = ($wcheck * 52); print "Please enter 6 numbers for the lottery: \n"; while ($count < 6) { $count++; print "Enter lottery number $count: "; chomp(my $num = <>); $count-- and print "That is not a valid input, please enter a numb +er between 1 and 54\n" and next if $num > 54 || !($num =~ /^\d+$/); $pick{"$count"} = "$num"; } ## Start our search! while () { $plays++; undef $win; my $i = 0; while ($i <= 6) { $i++; $rand{$i} = int(rand(54)) + 1;} foreach my $x (keys (%rand)) { foreach my $y (keys(%pick)) { $win++, next if $pick{$y} == $rand{$x}; } } $money += 1000000 and last if $win == 6; $money += 1000 if $win == 5; $money += 100 if $win == 4; $money += 5 if $win == 3; print "We won \$$money dollars so far, in $plays plays\n"; } print "We won \$$money dollars in $plays plays!\n"; ## Figure out how long it took us to hit the jackpot and print finding +s if ($plays >= $week) { $years = sprintf "%.1f", ($plays / $week); print "It took us $years years to hit the jackpot at $wcheck plays + a week. We won \$$money dollars!\n"; } else { print "It took us less than a year to hit the jackpot. We won \ +$$money dollars!\n"; }

In reply to Simple Lottery by xgunnerx

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (9)
As of 2024-04-18 09:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found