03-09-2012, 03:16 AM
(This post was last modified: 03-09-2012, 03:19 AM by AceInfinity.)
Code:
#!/usr/bin/perl
use warnings;
use strict;
sub GameStart {
my $target = int(rand(101));
print "Guess my number from 0 - 100!\n";
print "Enter your guess: ";
my $tries = 0;
my $game = 0;
while (!$game) {
my $guess = <STDIN>;
if ($guess == $target) {
print "That's it! You guessed correctly!\n";
$game = 1;
} elsif ($guess gt $target) {
print "Your number is bigger than my number, try again:\n";
} elsif ($guess lt $target) {
print "Your number is less than my number, try again:\n";
}
$tries ++;
}
print "It took you $tries tries\n";
}
GameStart
here's what I came up with, anything you don't understand just ask... I think everything here is pretty basic to look at an analyze, but in the event you don't see how something works by looking at it then just reply here.
Win/Loss is basically the same principle as the # of tries loop i've added in here.