Write a script that creates a craps game and meets the following requirements. N
ID: 3552455 • Letter: W
Question
Write a script that creates a craps game and meets the following requirements. Name the script craps.sh The script will get 2 random numbers between 1-6. The script will display each number, and the sum. If the sum is 2, 3, or 12 the user loses. Print an appropriate message. If the sum is 7 or 11 the user wins. Print an appropriate message. If the sum is 4, 5, 6, 8, 9, 10 this becomes the "point". The user will keep "rolling" until they get the point (they win) or 7 (they lose). Print an appropriate message. Once the user has won or lost, ask if the user wants to try again. If so, start the game again. If not, exit.Explanation / Answer
#!/bin/bash
flag=1
temp=1
while [ $flag -le 1 ]
do
n=$((RANDOM % 6+1))
#echo $n
q=$((RANDOM % 6+1))
echo two numbers are:$n,$q
let sum=$n+$q
echo there sum is $sum
if [ "$sum" -eq 2 ] || [ "$sum" -eq 3 ] || [ "$sum" -eq 12 ];then
echo "you lose"
echo do you want to continue 1/2?
read flag
#if [ $ans -eq 0 ];then
#flag=2
#fi
fi
if [ "$sum" -eq 7 ] || [ "$sum" -eq 11 ];then
echo "you win"
echo do you want to continue 1/2?
read flag
fi
flag=$temp
done
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.