In: Computer Science
Here is a script created a few years back. It has a few issues. See if you can make it work.
#!/bin/bash
# created by Your Name
# date
quit=no
while [ $quit = no ]
do
cat <<++
1) Roll Again?
2) Quit
++
# code to roll dice
read selection
case $selection in
1)
echo “Enter a number between 1 and 10”
read repeats
let seed=0
let r=0
while [ $r -le $repeats ]
do
let seed=7621*$seed+1
let n=5*$seed/10000000+1
let r=$r+1
done
echo $n
;;
2)
quit=yes
;;
esac
done
Answer: I ran the same code without any issues, please leave a comment if it doesn't work for you. I have put some echo statements to print the values. Hope this helps, good luck!
Output:
Code:
#!/bin/bash
# created by Your Name
# date
quit=no
while [ $quit = no ]
do
cat <<++
1) Roll Again?
2) Quit
++
# code to roll dice
read selection
case $selection in
1)
echo 'Enter a number between 1 and 10'
read repeats
let seed=0
let r=0
while [ $r -le $repeats ]
do
#!/bin/bash
# created by Your Name
# date
quit=no
while [ $quit = no ]
do
cat <<++
1) Roll Again?
2) Quit
++
# code to roll dice
read selection
case $selection in
1)
echo 'Enter a number between 1 and 10'
read repeats
let seed=0
let r=0
while [ $r -le $repeats ]
do
let seed=7621*$seed+1
echo "The seed : $seed"
let n=5*$seed/10000000+1
echo "The value of n : $n"
let r=$r+1
echo "The value of r : $r"
done
echo $n
;;
2)
quit=yes
;;
esac
done
let seed=7621*$seed+1
echo "The seed : $seed"
let n=5*$seed/10000000+1
echo "The value of n : $n"
let r=$r+1
echo "The value of r : $r"
done
echo $n
;;
2)
quit=yes
;;
esac
done