Created
April 18, 2010 23:47
-
-
Save xenoterracide/370622 to your computer and use it in GitHub Desktop.
Guess a number game
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
# guess a number game | |
use feature 'say'; | |
use strict; | |
use warnings; | |
say "welcome"; | |
my $winning_num = 5; | |
my $guess = 0; #initialize outside of loop so loop executes properly | |
until ( $guess == $winning_num ) { | |
say "Guess a number between 1 and 10: "; | |
# get the number from the user | |
$guess = readline(*STDIN); | |
# check to see if we have a winner, or the guess is too high, or too low. | |
if ( $guess == $winning_num ) { | |
say "You Win!"; | |
} | |
elsif ( $guess > $winning_num ) { | |
say "Too high"; | |
} | |
else { | |
say "Too low"; | |
} | |
} | |
say "Game over!"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment