Home‎ > ‎CIS 98‎ > ‎

Lab 11: User Input


The purpose of this lab is to add a looping construct along with decision constructs to produce two interactive scripts.  

Part 1: A Game 

This script uses a random number generator to obtain a number from 1 to some large number (but not over 32768) and then asks the user to guess the number. Each time the user guesses a number, the script will tell the user whether the number guessed was too low or too high. The script will continue to prompt the user for another guess until the correct number is entered. When the correct number is entered the script will terminate with a message displaying the correct number and how many guesses were made. 

Example Output:
$ game
Guess a number from 1 to 32768: 16000
Too low, guess again: 24000
Too low, guess again: 28000
Too high, guess again: 26000
Too high, guess again: 25000
Too low, guess again: 25500
Too high, guess again: 25250
Too high, guess again: 25125
Too high, guess again: 25064
Too high, guess again: 25033
Congratulations!! You guessed the number 25033 in 10 guesses.

When the program starts it should test if an environment variable called $SETNUMBER is set. If so, the program should use the value in $SETNUMBER rather than picking one at random. 

Extra Credit: Make your program check that the input is a number. If the input is not a number print the string "Guess again." 

Part 2: A Menu

Write a menu program called mshell that allows a user to choose among the following options:
  1. Middle Earth 
  2. Status reports 
  3. File Management 
  4. Games 
  5. Exit 
The program should iteratively display the above menu on the screen reading the input from the user. Simple error checking should be done in the event the user doesn't enter a valid menu option. The program should terminate when the user selects the Exit option. For each menu option selected, simply supply a stub function that echos the selection they made. For example: 

Example stub function:
middleearth() {
  echo "You selected 1. Middle Earth"

Turn In 

The following files should appear in your ~/lab11 directory
  • ~/lab11/game
  • ~/lab11/mshell


  • 10 points for game
  • 10 points for mshell