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
MVC Framework The ASP.NET MVC Structure is a web program framework that tools the model-view-controller (MVC) design. According to ASP.NET, it allows application designers to devel

Shopping Cart Purpose – Allows user to browse while keeping track of the items in which they will purchase at the end on the order page link and this will give a final price for al

What are the main pros and cons of assembly programming language?

Develop (i) a context diagram, and (ii) a use case diagram to model the following functionalities of an online brokerage house. eBroker is a discount online broker. An account h

Although the Document object's write()and writeln() methods are part of the DOM, they cannot be used to change content after a Web page has been rendered. You can write code that e

Windows Communication Foundation The Microsoft windows Interaction or communication foundation (or WCF), formerly known as "Indigo", is an application selection program (API) in th

Create the class Robot described in the Karel++ book. Description: The Robot class described in the Karel++ text is a derived class of ur_Robot. Create class Robot as a d

#questCustomers of a particular restaurant are described with some categories. If the categories indicate the customer is a senior citizen, or the customer works for the restaurant

I need someone to make an ER diagram.

Your solution to the problem should be housed within a while loop, which allows the grader to test your solution repeatedly without having to re-execute the script, as shown in cla