53.2k views
5 votes
Create a PERL script for a number guessing game. Here are the requirements: a. Your program generates a random number between 100 and 200 and keeps asking the user to guess the number until the user guesses it correctly. b. If the user guesses a number that is lower or higher than the number to be guessed then indicate that information to the user as a ‘low guess’ or a ‘high

1 Answer

4 votes

Answer:

see explaination

Step-by-step explanation:

Perl Program

#perl 5.22.1

#

# Hello World Program in Perl

#

$guss = 7;

$random_number = int(rand(100)) + 100;

print "Your name please: ";

my $name = <STDIN>;

chomp $name;

#print " '$random_number' ";

print "You Have 7 Gusses to Find Number\\";

print "Enter a number between 100 and 200\\";

my $num = <STDIN>;

chomp $num;

while( $guss > 0 )

{

if( $num == $random_number)

{

print ("Congratulations you Win the game in '$guss' gusses");

last;

}

elsif( $num < $random_number )

{

print ("Low Guss Try Again \\");

}

else

{

print ("High Guss Try Again \\");

}

my $num1 = <STDIN>;

chomp $num1;

$num = $num1;

$guss = $guss-1;

}

if($guss == 0)

{

print "You reached maximum gusses. Better Luck Next Time\\";

}

open(my $fh, '>', 'report.txt');

print $fh " '$name' '$guss'\\";

close $fh;

print "done\\";

User Scarhand
by
4.7k points