Results 1 to 9 of 9
  1. #1
    Join Date
    Mar 2009
    Posts
    2

    Unanswered: shell script that emulates a simple number guessing game

    Hello everyone,

    I need your help. Im not familiar with Unix Shell Script. Help me to create shell script that emulates a simple number guessing game.

    1) Preset an integer from the range of 1 to 100 in your script for the user to guess.
    2) Start the game by asking the user to enter his/her name and, the script will display a welcoming message to the user followed by his/her given name. 3) Next, prompt the user to guess the number by entering an integer from the range of 1 to 100.
    4) Allow the user to guess until he/she got the correct guess, and display a
    congratulatory message.
    5) Provide a hint for the user each time he/she entered a guess by displaying whether the user should guess lower or higher than 25, 50 or 75.

    Any help will be appreciated. Thanks

  2. #2
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    I need your help. Im not familiar with Unix Shell Script. Help me to create shell script that emulates a simple number guessing game.
    is this for work or do you just want us to do your homework?

  3. #3
    Join Date
    Mar 2009
    Posts
    2
    this is for work..

  4. #4
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Thumbs down Teacher's assignment?

    Looks more like HOMEWORK to me.
    What have you tried so far?

    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

  5. #5
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Perhaps he works for the U.S. Department of Commerce Bureau of Economic Analysis, and has been tasked with developing a more accurate method of creating financial forecasts?
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  6. #6
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,800
    Provided Answers: 11
    What you really need is a Requirements Guessing script. If you make a successful one of those, you will be a millionaire....for what that's worth, these days.

  7. #7
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    I think the following works:
    Code:
    #!/bin/sh
    n=0
    while [ $n -lt 123 ]; do
    nzdf=`ps | sum | cut -c4-5`
    n=`expr $n + 1`
    wrd=To
    done
    n=`echo mbk nzdf -sol101 | sed 's/.*/0/'`
    while [ `expr $n  + 4` -ne `expr $nzdf  + 4` ]; do
    echo -n "Your guess:" | tr 'a-z' 'A-Z'
    read n
    if test `expr $n  + 4` -gt `expr $nzdf  + 4`
    then
    echo "$wrd big" | tr 'a-z' 'A-Z'
    fi
    if test `expr $n  + 4` -lt `expr $nzdf  + 4`
    then
    echo "$wrd small" | tr 'a-z' 'A-Z'
    fi
    done
    echo "Correct" | tr 'a-z' 'A-Z'
    exit -4
    I should point out this uses an NZDF approach to design but I think this is exactly what's required for this particular OP.
    Last edited by mike_bike_kite; 03-19-09 at 13:05.

  8. #8
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    Dear ImSorry

    Did this get a good mark and did the lecturer have any follow up questions?
    I'm just curious

    Mike

  9. #9
    Join Date
    Nov 2010
    Posts
    1

    a couple small changes

    That works very well. How could I change that so that it uses The RANDOM function to genrate a larger range of numbers, and only lets the user have 16 tries?

    Also, if your really feeling nice how would I write a function called "checknum" that checks the number as opposed to the way it is currently written? and incorporate it into the code.

    If you respond to this...thank you!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •