Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Simple Blackjack progam help

by moritz (Cardinal)
on Oct 13, 2012 at 17:48 UTC ( #998863=note: print w/ replies, xml ) Need Help??


in reply to Simple Blackjack progam help

First of all, please start your code with

use strict; use warning;

and declare your variables with my when you use them first.

Some others errors I noticed at first glance:

When you read in a line with $variable = <STDIN>, then the variables has a trailing newline character. Usually you don't need that, so remove it by calling chomp $variable.

if ($another == 'y')

== is for comparing numbers, but 'y' isn't a number. Instead use

my $another = <STDIN>; chomp $another; if ($another eq 'y') { ... }

next:

$draw1 = int &draw;

Your draw subroutine already calls int, there's no need to do it twice

sub draw { $draw = int rand(10); }

That returns an integer between 0 and 9, not between 1 and 10.

Please search a bit for debugging tips & tricks here on perlmonks, there a quite a few that could have caught many of these errors, and probably many other errors that still lurk in your code.


Comment on Re: Simple Blackjack progam help
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://998863]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (12)
As of 2014-07-28 17:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (204 votes), past polls