Im trying to create a craps game on linux mint but im definitely not proficient with it. I'm a new student to this class and its done online. I seen a post that was already made with the exact question and requirements that I need to use for my script, but when I run the command it processes wrong, it goes like this... 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. BONUS: +10 possible: Implement a wagering system. Before each initial roll ask the user how much they wish to wager, and keep track of how much they have won/lost. I have been trying to get this for days and can't figure it out... my professor won't help and doesn't provide a text book.
# craps.sh program inn bash shell
# $RANDOM returns a different random integer at each invocation.
# generate_random_number function which returns sum of
# 2 random number between 1 and 6
generate_random_number()
{
RANGE=6
#get 2 random numbers
number1=$RANDOM
number2=$RANDOM
# get it between 1 and 6
number1=$((($number1%$RANGE)+1))
number2=$((($number2%$RANGE)+1))
echo number 1 is $number1
echo number 2 is $number2
# add 2 numbers
sum=$(($number1+$number2))
echo sum is $sum
#return the sum
return $sum
}
# play_game() function invoked whenever user wants to play
play_game(){
# first throw
generate_random_number
sum=$?
# check if win or lost
if(($sum==2 || $sum==3 || $sum==12))
then
# lost then subtract wager from total amount
amount=$(($amount-$wager))
echo You Lost $wager$
fi
if(($sum==7 || $sum==11))
then
# win then add wager to total amount
amount=$(($amount+$wager))
echo You Won $wager$ more
fi
if(($sum==4 || $sum==5 || $sum==6 || $sum==8 ||$sum==9 || $sum==10))
then
# store current sum as point and throw until point
# appears or 7
point=$sum
generate_random_number
value=$?
while (( $value!=$point && $value!=7 ))
do
generate_random_number
value=$?
done
# if point appears then win else lost
if(($value==$point))
then
amount=$(($amount+$wager))
echo You Won $wager$ more
else
amount=$(($amount-$wager))
echo You Lost $wager$
fi
fi
# user input to try again
read -p "Try again?Y/N " again
if [ "$again" = "Y" ]; then
# play_game to play again
play_game
else
# else display the total amount won or lost
if(( $amount >= 0))
then
echo You Won $amount$
else
amount=$(($amount*-1))
echo You Lost $amount$
fi
echo bye
fi
}
# initialize amount to 0
amount=0
# before first throw get the wager amount
read -p "Enter wager amount : " wager
play_game
echo
cmd /x
Refer below screenshots for indentation and output
Im trying to create a craps game on linux mint but im definitely not proficient with...
C# Code: Write the code that simulates the gambling game of craps. To play the game, a player rolls a pair of dice (2 die). After the dice come to rest, the sum of the faces of the 2 die is calculated. If the sum is 7 or 11 on the first throw, the player wins and the game is over. If the sum is 2, 3, or 12 on the first throw, the player loses and the game is...
Write a C++ game that plays Craps. Craps is a game played with a pair of dice. The shooter (the player with the dice) rolls a pair of dice and the number of spots showing on the two upward faces are added up. If the opening roll (called the ‘come out roll’) is a 7 or 11, the shooter wins the game. If the opening roll results in a 2 (snake eyes), 3 or 12 (box cars), the shooter loses,...
III. Overview & Requirements: The following description has been adopted from Deitel & Deitel. One of the most popular games of chance is a dice game called "craps," which is played in casinos and back alleys throughout the world. The rules of the game are straightforward: A player rolls two dice. Each die has six faces. These faces contain 1, 2, 3, 4, 5, and 6 spots. After the dice have come to rest, the sum of the spots on...
Write a c++ program that simulates a million of games in craps. I am having a trouble getting to loop a million of times. I am trying to use a const for a million. This is the code so far. #include <iostream> #include <cstdlib>// contains prototypes for functions srand and rand #include <ctime>// contains prototype for function time #include <iomanip> using namespace std; int rollDice(); // rolls dice, calculates and displays sum void printstats(); int totroll = 0, games, point,...
Game of Craps C++ #include <iostream> using namespace std; void roll (int *); // using pointer to catch the random variable value of two dicerolls at one time . //these global variable with static variable win use to operate the working of code . //static win, account because two times input given by user to add the diceroll with win number and //account (means balance of user) . static int account = 100; static int win = 0; int bet...
I need help fixing my python3 code. I am trying to get my Monty hall game working correctly. Below is my code. When I run the code it repeats the first question and doesn't work until the 3rd attempt or sometimes more than that. How do I fix this? I also need to be able to make it run 5 times in a row.(like ask the user at least 5 times, so it is re-playable. I added a image of...
Please i need helpe with this JAVA code. Write a Java program simulates the dice game called GAMECrap. For this project, assume that the game is being played between two players, and that the rules are as follows: Problem Statement One of the players goes first. That player announces the size of the bet, and rolls the dice. If the player rolls a 7 or 11, it is called a natural. The player who rolled the dice wins. 2, 3...
Use Dev C++ for program and include all of the following. Im lost. Make sure the user enters a letter of R, P, or S and the computer generates a number between 0-2 and changes that number to a letter of R, P or S, using a switch. Make sure the user knows why he/she has won or lost – print a message like “Paper covers Rock” or “Scissors cuts Paper”. Ask the user how many times he/she wants to...
Write a Java application program that plays a number guessing game with the user. In the starter code that you are given to help you begin the project, you will find the following lines of code: Random generator = args.length == 0 ? new Random() : new Random(Integer.parseInt(args[0])); int secret = generator.nextInt(100); You must keep these lines of code in your program. If you delete these lines, or if you change thse lines in any way, then your program...
For a C program hangman game: Create the function int play_game [play_game ( Game *g )] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) (Also the link to program files (hangman.h and library file) is below the existing code section. You can use that to check if the code works) What int play_game needs to do mostly involves calling other functions you've already...