Perl: Game - Find out the Number - by Eun Bae Kim (08/26/2018)
 

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
  
use strict;

my $iMax = 1000000;
my $iQuestion = int(rand($iMax) + 1);

my $iCnt = 0;

while (1) {
	print "Input an integer between 1 to $iMax.\n";
	print "Your Number = ";
	my $iYours = <STDIN>;

	if ($iYours > $iMax) {
		print "It is so big!!! Retry!!\n";
		next;
	}
	if ($iYours == 0) {
		print "Retry!!\n";
		next;
	}

	$iCnt++;

	if ($iYours > $iQuestion) {
		print $iCnt."  "."Bigger!!!\n";
	} elsif ($iYours < $iQuestion) {
		print $iCnt."  "."Smaller!!!\n";
	} else {
		print $iCnt."  "."Great!!!!!!!!!\n";
		last;
	}
	print "==============================\n";
}