~~~~~~~~~Posted below is a problem in MATLAB, please answer and provide the corr
ID: 3863746 • Letter: #
Question
~~~~~~~~~Posted below is a problem in MATLAB, please answer and provide the correct coding and functions. Thanks!~~~~~~~~~~~~~~
Problem 2: dice777 Game is a very simple game played with two dice. The player simply bets on whether the sum of the two dice when rolled will be Under 7, Over 7, or Equal to 7. Write a function called dice777. To help you shuffle the dice well, include this command in your code: rng( shuffle'). Make sure you initiate this command before you roll your dice. This command randomly seeds the random function you will be using to generate the results of the dice. Your function will prompt the user to input how much money he/she wishes to wager. Also prompt the user to place his/her bet: Under 7, Over 7, Equals 7. Before the user places the bet, provide the user with the rules of the game as shown below in the output printout. Once the bet is placed, the dice is rolled twice and the sum of the rolls are calculated to determine a win or a loss. Use the following to roll your dice: Dicel randi [i 6,1); Dice2 randi([1 6,1); [Note: randi li 6,1) creates one integer value in the range of 1 to 6]. The payout depends on the bet. If the player correctly bet Under 7 or Over 7, the payout is 1:1 (i.e., if the user bets S5 he/she wins $5. If the player correctly bets Exactly 7, the payout is 10:1 (i.e., if one bets S10, the win is $100). You may want to cap how much one can bet. Below is a sample run and the corresponding output dice 777 How much money do you want to bet $1 to $10:10 Betting rules: Select 1 if you think the sum of the two dice will be LESS than 7 Select 2 if you think the sum of the two dice will be MORE than 7 Select 3 if you think the sum of the two dice will be EXACTLY 7 And your bet is 3 Ro You won your bet and your payout is $100 9%%%%, %%6%6% 9%Explanation / Answer
function[] = dice777()
rng('shuffle');
% disp('How much money do you want to bet($1 to $10): ');
bet_cost = input('How much money do you want to bet($1 to $10): ');
if(bet_cost>10 || bet_cost<1)
bet_cost = input('Please bet within range.How much money do you want to bet($1 to $10): ');
end
fprintf('Betting rules: Select 1 if you think the sum of the two dice will be LESS than 7 Select 2 if you think the sum of the two dice will be MORE than 7 Select 3 if you think the sum of the two dice will be EXACTLY 7 ');
% disp('And you Bet is: ');
bet_type = input('And you Bet is: ');
Dice1 = randi([1 6],1);
Dice2 = randi([1 6],1);
sum = Dice1 + Dice2;
fprintf('Roll 1 = %d, Roll 2 = %d, and the sum is = %d ', Dice1, Dice2, sum);
if(sum < 7)
t=1;
elseif(sum > 7)
t=2;
else
t=3;
end
if(t == bet_type)
if(t == 3)
fprintf('You won your bet and your payout is $%d ', bet_cost*10);
else
fprintf('You won your bet and your payout is $%d ', bet_cost);
end
else
fprintf('You lost your bet ');
end
end
Sample output of the code:
How much money do you want to bet($1 to $10): 2
Betting rules:
Select 1 if you think the sum of the two dice will be LESS than 7
Select 2 if you think the sum of the two dice will be MORE than 7
Select 3 if you think the sum of the two dice will be EXACTLY 7
And you Bet is: 3
Roll 1 = 1, Roll 2 = 4, and the sum is = 5
You lost your bet
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.