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
Calculate the total price based on several key parts required to build a state-of-the-art gaming computer. The user will have the option of selecting different parts.

.NET class library .NET structure comes with just one category selection. And that all developers need to learn!! Whether they create the value in C# or VB.NET or J#, it doesn't

what is the difference between class and interface

Project2: A Simple Distributed Computing Platform (Due at 11:59:59pm on 04/12/2012 (EST)) Description: You are asked to develop a replicator (client) that distributes a large job

How Can I Retrive Unicode CSV File the ADO.net VB.net

We want to create a structure that will represent a deck of cards  (not necessarily full). Each card has a character (between  '2'  to  '9' and  'T',  'J',  'Q',  'K',  'A') and a

You get a contract to implement a simple Java application that process NBA team roster : your application has to read the NBA team roster from a text file and then print each playe

* Comments in your code are required * Main Program Operation:  # Your program should first prompt the user for an integer to seed the random number Generator. "Enter an seed

I do have an assignment in operating systems programming ... how can i attach my file?

( Airline Reservations System ) A small airline has just purchased a computer for its new automated reservations system. You have been asked to develop the new system. You are to w