Question

Build a script using matlab that, when run, will produce two cards from a deck of...

Build a script using matlab that, when run, will produce two cards from a deck of 52 and will output the face and suit of each card as well as the sum of the face value of the two cards. (Assume 2 – 9 carry their own value, 10 – K carry a value of 10, and A is 11.) If the user’s sum is 21, say, “Jackpot!” If it is 15 or less, say, “Hit!” If neither, say, “Stay!”

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

%First we will generate a random suit and then generate a ranfom card

x = [1,2,3,4,5,6,7,9,10,10,10,10,11] 
face = ['diamonds';'hearts';'spades';'clubs']  
pos1 = randi(length(face))
pos2 = randi(length(face)) 
card1_suit = face(pos1)
card2_suit = face(pos2) 
pos1 = randi(length(x))
pos2 = randi(length(x)) 
card1_face = x(pos1) 
card2_face = x(pos2) 
disp ('Card 1 is:') 
disp(card1_suit) 
disp(card1_face) 
disp ('Card 2 is:') 
disp(card2_suit) 
disp(card2_face) 
sum = card1_face+card2_face 
if sum==21 
disp ('Jackpot') 
else if sum<16 
disp ('Hit') 
else 
disp ('stay') 
end 
Add a comment
Know the answer?
Add Answer to:
Build a script using matlab that, when run, will produce two cards from a deck of...
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
  • In the game of blackjack, the player is initially dealt two cards from a deck of...

    In the game of blackjack, the player is initially dealt two cards from a deck of ordinary playing cards. Without going into all the details of the game, it will suffice to say here that the best possible hand one could receive on the initial dear is a combination of an ace of any suit and any face card or 10. What is the probability that the player will be dealt this combination?

  • 4 cards are randomly drawn from a standard deck of playing cards. What is the prob-...

    4 cards are randomly drawn from a standard deck of playing cards. What is the prob- ability that all their suits are different? Hint: There are 52 cards in a standard deck of playing cards. A card can have 4 different suits: diamond ( ♦ ), club ( ♣ ), heart ( ♥ ), or spades ( ♠ ). There are 13 cards of each suit. Cards are further labeled by their rank: numbers 1 to 10 and three face...

  • A 10-card hand is dealt from an ordinary deck of 52 cards. Find the probability that...

    A 10-card hand is dealt from an ordinary deck of 52 cards. Find the probability that there are exactly 4 cards of one suit and 3 in two other suits.

  • Write a class named Card which will represent a card from a deck of cards. A...

    Write a class named Card which will represent a card from a deck of cards. A card has a suit and a face value. Suits are in order from low to high: Clubs, Diamonds, Hearts and Spades. The card values from low to high: 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, and Ace. Write a Deck class that contains 52 cards. The class needs a method named shuffle that randomly shuffles the cards in the...

  • In poker, there is a 52 card deck with 4 cards each of each of 13...

    In poker, there is a 52 card deck with 4 cards each of each of 13 face values. A full house is a hand of 5 cards with 3 of one face value, and 2 of another. Say you have been dealt your hand two cards up, three cards down, and the two cards you see are both 10’s. What is the probability that your hand is a full house, given this information? (It should read: "two cards up, three...

  • how many diamonds are in a deck of cards?

    A deck of cards contains 52 cards. They are divided into four suits: spades, diamonds, clubs and hearts. Each suit has 13 cards: ace through 10, and three picture cards: Jack, Queen, and King. Two suits are red in color: hearts and diamonds. Two suits are black in color: clubs and spades.Use this information to compute the probabilities asked for below and leave them in fraction form. All events are in the context that three cards are dealt from a...

  • In poker, there is a 52 card deck with 4 cards each of each of 13...

    In poker, there is a 52 card deck with 4 cards each of each of 13 face values. A full house is a hand of 5 cards with 3 of one face value, and 2 of another. Say you have been dealt your hand two cards up, three cards down, and the two cards you see are a king and a queen. What is the probability that your hand is a full house, given this information?

  • 1. A hand of four cards is drawn from a standard deck of 52 playing cards...

    1. A hand of four cards is drawn from a standard deck of 52 playing cards (without re- placement). Determine the probability that the hand contains: (a) four cards of the same value. (e.g. 20, 24, 26, 20). (b) two cards of one value and two cards of another value. (e.g. 3º, 2º, 24, 30) (c) four cards of the same suit. (e.g. 4♡, 2V, AV, K♡). (d) exactly two Queens. (e.g. KV, 36, QO, Qob) (e) exactly three spades....

  • a draw poker hand consists of 5 cards taken from a deck of 52 cards where...

    a draw poker hand consists of 5 cards taken from a deck of 52 cards where the order of the cards is irrelevant. assuming you are playing with an honest deck, find the probability of each of the following hands. a.) A "four of a kind" (four cards of the same value and a "kicker" of any other value) b.) A "flush" (all five cards of the same suit) c.) An "ace-high straight" ( 10, J, Q, K, A of...

  • if you draw two cards from a standard deck of 52 cards without replacement find: a

    if you draw two cards from a standard deck of 52 cards without replacement find:a. P(King first, Jack second)b. P( face card first, ace second)c. P(2 aces

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