944,182 Members | Top Members by Rank

Ad:
Jun 6th, 2007
0

Please need help with bash script

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jermane is offline Offline
1 posts
since Jun 2007
Jun 7th, 2007
0

Re: Please need help with bash script

use expr.
Reputation Points: 769
Solved Threads: 128
Banned
ithelp is offline Offline
1,910 posts
since May 2006
Jun 9th, 2007
0

Re: Please need help with bash script

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:
Shell Scripting Syntax (Toggle Plain Text)
  1. if test [rand1 = rand2] && [rand2 = rand3]
to this:
Shell Scripting Syntax (Toggle Plain Text)
  1. 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)
Reputation Points: 10
Solved Threads: 0
Light Poster
mittelgeek is offline Offline
37 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: Fedora Resolution
Next Thread in Shell Scripting Forum Timeline: shell script





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC