Write a perl program to design a computer game, Programming Languages

Write a Perl program ghici.pl, one of the simplest computer games. The program should generate a random integer between 1 and 1000 and asks the user to guess it. If the user ?nds the number, the program stops with a message. If not, the program adjusts the interval based on the user's guess and lets him try again. To generate a random integer, use function rand, documented in perldoc perlfunc.

despi@turing> ghici.pl
comp315@turing> ghici.pl
Enter a number between 1 and 1000: 1200
Please stay between 1 and 1000.
Enter a number between 1 and 1000: 500
Enter a number between 500 and 1000: 300
Please stay between 500 and 1000.
Enter a number between 500 and 1000: 750
Enter a number between 500 and 750: sir!
Please enter a number only.
Enter a number between 500 and 750: 625
Enter a number between 625 and 750: 684
Enter a number between 684 and 750: 712
Enter a number between 684 and 712: 694
Enter a number between 684 and 694: 689
Enter a number between 689 and 694: 692

You guessed it in 11 tries.

Notice how the program works:

  • it uses a dichotomic search based on user's answer to adjust the limits.
  • it tests if the answer is a number in between limits
  • it counts the number of tries.

What features would you like to add to this program? Write them down as a comment in the source code of ghici.pl.

Posted Date: 3/12/2013 1:42:43 AM | Location : United States







Related Discussions:- Write a perl program to design a computer game, Assignment Help, Ask Question on Write a perl program to design a computer game, Get Answer, Expert's Help, Write a perl program to design a computer game Discussions

Write discussion on Write a perl program to design a computer game
Your posts are moderated
Related Questions
Write a program to use a robot to move the stack of blocks from a source location to a target location, based. Movement of robot arms, picking and dropping, can be controlled usi

Write a program to draw the figure shown below. the program must provide: a. Close the fish's mouth slowly (at least 5 moves from the original position to close the mouth) b.

program for pyramid in shell script

Write a function called withdraw (in the file 'withdraw.m') that simulates withdrawing money from a bank account. The function takes a single input argument, a positive scaler doub

OTRS Customisation using Perl, MySQL Programming OTRS is a perl based open source issue ticket management solution. Default performance features 'note-internal' that is visible

Can you please make my assignment in 3 days?I will pay you good

2. TEST & AND TEST is like CMP, it is used for conditional statement, and doesn’t save the answer. AND is logical multiplication. 3. INS & IN IN is used for data transfer from I/O

A large logistics company requires a software system to support the business processes associated with managing shift patterns of employees and making the associated payments. The

Is it possible to get an assignment done within 2 hours

Windows Presentation Foundation Designed by Microsoft Technologies, the Microsoft Technologies windows Display Groundwork (or WPF) is a computer-software graphic subsystem for maki