Question

Hello, can anyone help me solve this using MATLAB? Will rate well, thank you. You are...

Hello, can anyone help me solve this using MATLAB? Will rate well, thank you.

You are playing a game where you roll a fair dice 7 times. We set the sum of maximum value and minimum value as S. If S is 2, 5, or 12, you win 3 times S dollars; that is respectively 6,15, or 36. If S is 7 or 11, you win 2 times S dollars; that is respectively 14 or 22. If S is anything else, you win no money. Write a function, called diceGame, which takes in a vector representing the dice values and returns the amount of money won.

For example: m = diceGame([1 2 3 4 5 6 1]) should return m = 14

m = diceGame([[1 1 1 1 1 1 1]]) should return m = 6

m = diceGame([2 1 2 2 5 1 5]) should return m = 0

Test your program for the following three cases:

m = diceGame([5 1 2 3 4 6 6])

m = diceGame([6 6 6 3 4 2 5])

0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.

clc
clear all
close all
format long
m = diceGame([1 2 3 4 5 6 1])


function m=diceGame(v)
m=0;
S=min(v)+max(v);
if(S==2|S==5|S==12)
m=3*S;
elseif(S==7|S==11)
m=2*S;
else
m=0;
end
end

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
Hello, can anyone help me solve this using MATLAB? Will rate well, thank you. You are...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • USE PYTHON ONLY Please write a Python program to let you or the user play the...

    USE PYTHON ONLY Please write a Python program to let you or the user play the game of rolling 2 dice and win/lose money. Initially, you have 100 dollars in your account, and the dealer also has 100 dollars in his/her account. You would be asked to enter a bet to start the game. If your bet is zero, the game would be stopped immediately. Otherwise, dealer would roll 2 dice and get a number from ( random.randint(1, 6) +...

  • WITHOUT FUNCTIONS. Could anyone help me solve this problem not using the function ? Thanks a...

    WITHOUT FUNCTIONS. Could anyone help me solve this problem not using the function ? Thanks a lot. Pig Dice Game Pig is a simple two player dice game, played with one die. The first player to reach or surpass 50 is the winner. Each player takes a turn rolling the dice. They add to the pot with each roll, having to decide to roll again and increase the pot, or cash out. The risk being they could lose the amount...

  • Can anyone help me with this java program? We are still very early with lessons so...

    Can anyone help me with this java program? We are still very early with lessons so no advanced code please. And if you comment throughout the code that would be incredibly helpful. Thank you Create 2 Java files for this assignment: Die.java and TestDie.java Part 1 - The Die Class             The program Design a Die class that contains the following attributes: sides: represents how many sides a dice has. A dice usually has 6 sides but sometimes could have...

  • This is in C++. The program needs to show the points as well. The blue boxes...

    This is in C++. The program needs to show the points as well. The blue boxes show below are the output and it should look like that. Thanks (Game: craps) Craps is a popular dice game played in casinos. Write a program to play a variation of the game, as follows: Roll two dice. Each die has six faces representing values 1, 2, ..., and 6, respectively. Check the sum of the two dice. If the sum is 2, 3,...

  • Intro to Java. Can someone please help me answer this question. Create a java program playing...

    Intro to Java. Can someone please help me answer this question. Create a java program playing the game of craps with a random number generator. Write a method craps that plays the game of craps and it should return a 1 representing a win, a 2 representing a loss, and a 0 representing the need to toss the pair of dice again. The main method should ask how many games you wish to play then call the method craps. Main...

  • You are on a TV show. You have been asked to either play a dice game...

    You are on a TV show. You have been asked to either play a dice game or accept a $50 bill. The dice game works like this: You roll four dice. For each dice; if you roll a 1, 2, or 3, you win $60. If you roll a 4 or 5, you lose $30. If you roll a 6, you lose $70. Determine expected value of the dice game? Do you play the game, or take the money? Explain...

  • Is anyone familiar with programming in Swift? That is the language the solution must be implemented...

    Is anyone familiar with programming in Swift? That is the language the solution must be implemented in. Problem 2: Mini Snakes and Ladders (3 points) Snakes and laders You are going to build a function that mimics the classic board game snakes & ladders. The game from square 1 to square 30. On the virtual board the ladders are positioned at 1, 4, and 13, which take you to 23, 15, and 29 respectively. The snakes are at positions 16,...

  • Hello, Could you please help me code this program in Java? It is important that all...

    Hello, Could you please help me code this program in Java? It is important that all rules are carefully followed. Using the PairOfDice class from PP 4.9, design and implement a class to play a game called Pig. In this game, the user competes against the computer. On each turn, the current player rolls a pair of dice and accumulates points. The goal is to reach 100 points before your opponent does. If, on any turn, the player rolls a...

  • Suppose someone gives you 8 to 2 odds that you cannot roll two even numbers with...

    Suppose someone gives you 8 to 2 odds that you cannot roll two even numbers with the roll of two fair dice. This means you win ​$8 if you succeed and you lose ​$2 if you fail. What is the expected value of this game to​ you? Should you expect to win or lose the expected value in the first​ game? What can you expect if you play​​​​​​​ 200 ​times? Explain.​(The table will be helpful in finding the required​ probabilities.)...

  • For this lab you will write a Java program that plays the dice game High-Low. In...

    For this lab you will write a Java program that plays the dice game High-Low. In this game a player places a bet on whether the sum of two dice will come up High (totaling 8 or higher), Low (totaling 6 or less) or Sevens (totaling exactly 7). If the player wins, they receive a payout based on the schedule given in the table below: Choice Payout ------ ------ High 1 x Wager Low 1 x Wager Sevens 4 x...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT