If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > shell script that emulates a simple number guessing game

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-13-09, 10:36
ImSorry ImSorry is offline
Registered User
 
Join Date: Mar 2009
Posts: 2
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
Reply With Quote
  #2 (permalink)  
Old 03-13-09, 11:19
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,517
Quote:
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?
Reply With Quote
  #3 (permalink)  
Old 03-13-09, 11:21
ImSorry ImSorry is offline
Registered User
 
Join Date: Mar 2009
Posts: 2
this is for work..
Reply With Quote
  #4 (permalink)  
Old 03-13-09, 12:45
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,413
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
Reply With Quote
  #5 (permalink)  
Old 03-13-09, 12:55
blindman blindman is offline
World Class Flame Warrior
 
Join Date: Jun 2003
Location: Ohio
Posts: 11,556
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"
Reply With Quote
  #6 (permalink)  
Old 03-13-09, 12:59
MCrowley MCrowley is offline
Wage drone 24601
 
Join Date: Jan 2003
Location: Massachusetts
Posts: 4,784
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.
Reply With Quote
  #7 (permalink)  
Old 03-13-09, 13:11
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,517
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.
Reply With Quote
  #8 (permalink)  
Old 05-04-09, 11:27
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,517
Dear ImSorry

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

Mike
Reply With Quote
  #9 (permalink)  
Old 11-29-10, 20:01
catchingcadence catchingcadence is offline
Registered User
 
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!!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On