And here it is.
I'm just, JUST learning how to use perl, and how to do any sort of programming in general. I'm trying to self-teach and have read a book on C programming and wanted to try PERL. I'm really very green at this and don't want to give up, but its not always easy to move forward without help so here goes. I have this simple, simple program that I am trying to write based off of some other examples I have read. Unfortunately, in order to get it to run in five or less trys, I do not think I'm executing the incrementing correctly. Can anyon take a quick look, point, laugh, and maybe guide me toward the sun?
So much appreciated, thank you.
[CODE=perl]#!/user/bin/perl
my $count = 0;
my $num = int(rand (21));
my $guess = <STDIN>;
do {
print "Guess a number from 1-20:";
if($guess == $num) {
print "You win. Go start your 1-900 number
immediately.\n" ;
}
elsif( $guess > 20) {
print "Uhh, lets try that again. A number,
one through 20. Go:\n";
}
elsif( $guess < 1) {
print "No dice. 1-20. Try again.\n";
}
$count++;
while ($guess!= $num) {
if ($count <=4) {
print "Nope. Guess again.\n";
}
else ($count == 5) {
print "You lose. Don't quit your day job.\n" || die;
}[/CODE]
I'm just, JUST learning how to use perl, and how to do any sort of programming in general. I'm trying to self-teach and have read a book on C programming and wanted to try PERL. I'm really very green at this and don't want to give up, but its not always easy to move forward without help so here goes. I have this simple, simple program that I am trying to write based off of some other examples I have read. Unfortunately, in order to get it to run in five or less trys, I do not think I'm executing the incrementing correctly. Can anyon take a quick look, point, laugh, and maybe guide me toward the sun?
So much appreciated, thank you.
[CODE=perl]#!/user/bin/perl
my $count = 0;
my $num = int(rand (21));
my $guess = <STDIN>;
do {
print "Guess a number from 1-20:";
if($guess == $num) {
print "You win. Go start your 1-900 number
immediately.\n" ;
}
elsif( $guess > 20) {
print "Uhh, lets try that again. A number,
one through 20. Go:\n";
}
elsif( $guess < 1) {
print "No dice. 1-20. Try again.\n";
}
$count++;
while ($guess!= $num) {
if ($count <=4) {
print "Nope. Guess again.\n";
}
else ($count == 5) {
print "You lose. Don't quit your day job.\n" || die;
}[/CODE]
Comment