User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 456,429 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,626 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser: Programming Forums
Views: 1206 | Replies: 2
Reply
Join Date: Jun 2007
Posts: 1
Reputation: jermane is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
jermane jermane is offline Offline
Newbie Poster

Help Please need help with bash script

  #1  
Jun 6th, 2007
Hello,

i'm taking my first class in linux and i am working on a script that will display 3 random number and display amount of jackpot, the script should act like a "slot amchine game". I have two problem one is the statement "You are a loser" is diaply even when the number is a match and should be diplayed only if not match (I can not get the "You won" to diplay) the second problem is that the Jackpot keeps display 25 and is not increasing.
Any help would be great.


_________________________________


#This is a slot machine game that uses 3 random to generate a winner or loser, it also display the jackpot amount.

#! bin/bash
rand1=$(($RANDOM % 6)) #Generate the random numbers
rand2=$(($RANDOM % 6))
rand3=$(($RANDOM % 6))
echo ""
echo ""
echo ""
echo "THE JACKPOT IS:" $((total = total + 25)) #Display the JACKPOT AMOUNT
echo ""
echo ""
echo ""
echo "YOUR NUMBERS ARE:" "[$rand1]" "[$rand2]" "[$rand3]" #Display random number
#echo "THE JACKPOT IS:" $((tota1 = total + 25))
echo ""
echo ""
echo ""
echo ""
if test [rand1 = rand2] && [rand2 = rand3] #Test for winner and loser
then
echo "YOU WON"
else
echo "YOU ARE A LOSER"
fi
echo ""
echo ""
echo""
_______________________________________
Last edited by jermane : Jun 6th, 2007 at 9:16 am.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2006
Location: ★ ijug.net ★
Posts: 1,012
Reputation: ithelp will become famous soon enough ithelp will become famous soon enough 
Rep Power: 6
Solved Threads: 68
ithelp ithelp is offline Offline
Veteran Poster

Re: Please need help with bash script

  #2  
Jun 7th, 2007
use expr.
Reply With Quote  
Join Date: Aug 2005
Location: North of the equator, but south of anywhere it could get cold for long
Posts: 31
Reputation: mittelgeek is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
mittelgeek's Avatar
mittelgeek mittelgeek is offline Offline
Light Poster

Re: Please need help with bash script

  #3  
Jun 9th, 2007
Unfortunately, I need to rearrange the partitions on my laptop so that I can boot linux so I can't test your script out, but...

You might want to check out this for some tips on using the $RANDOM variable:
Getting Random Values in sh. [linuxgazette.net.]

You might want to change this:
if test [rand1 = rand2] && [rand2 = rand3]
to this:
if [$rand1 -eq $rand2] && [$rand2 -eq $rand3];
The test command and the symbol [ are the same.

Just a side note: You may want check on your coding style or lack there of. Indenting really helps debugging. I commend you on your documentation. Even though it is a pain, commenting helps tremendously when debugging; especially when it is three o'clock in the morning and you've staring at the code since one o'clock that afternoon, or when I have to come in after to to fix something. =8)
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Shell Scripting Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Shell Scripting Forum

All times are GMT -4. The time now is 1:26 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC