Question

In: Computer Science

Write a program in c++ that picks four cards from a deck of 52 cards and...

Write a program in c++ that picks four cards from a deck of 52 cards and computes the sum of the four cards. An Ace, King, Queen, and Jack represent 1, 13, 12, and 11, respectively. Your program should display the number of picks that yields the sum of 24.

You are not allowed to use arrays. Declare four variables to hold the card values.

Solutions

Expert Solution

Required program in c++ -->

#include <iostream>
#include <random>
int main()
{
int sum=0,count=0;
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> distr(1, 13); //range of random number 1-13
int a=distr(gen);    //generates a random number & stores the value in a
int b=distr(gen);    //generates a random number & stores the value in b
int c=distr(gen);    //generates a random number & stores the value in c
int d=distr(gen);    //generates a random number & stores the value in d
std::cout<<"Random card selected is: "<<a<<"\n"; //print random number of a
sum=sum+a; //value of a is added in sum
if(sum<=24){ //if sum is smaller or equal to 24
count++; //then count increases by 1
}
std::cout<<"Random card selected is: "<<b<<"\n"; //print value of b
sum=sum+b; //add b in sum
if(sum<=24){ //if sum is smaller or equal to 24
count++; //count increases by 1
std::cout<<"Random card selected is: "<<c<<"\n"; //print value of c
sum=sum+c; //add c in sum
if(sum<=24){ //if sum is smaller or equal to 24
count++; //count is increased by 1
std::cout<<"Random card selected is: "<<d<<"\n"; //print value of d
sum=sum+d; //d is added in sum
if(sum<=24){ //if sum is smaller or equal to 24
count++; //value of count increases by 1
std::cout<<"It takes "<<count<<"counts"<<"\n"; //print count
}
else{
std::cout<<"It takes "<<count<<"counts"<<"\n"; //print count
}
}
else{
std::cout<<"It takes "<<count<<"counts"<<"\n"; //print count
}
}
else{
std::cout<<"number of picks that yields the sum of 24 or less is : "<<count<<"\n"; //print count
}
}


Related Solutions

Play a blackjack. Write a Java program that starts from a deck of 52 cards and...
Play a blackjack. Write a Java program that starts from a deck of 52 cards and one player plays again a dealer. Use a simple rule explained here. Ace can be counted as 1 only for simplicity. Jack, Queen, King are counted as 10. At the beginning, player receives two cards. Dealer receives two cards, but shows one and hides one. Program asks player if player wants to receive another card or not. (player can continue to receive new cards...
Four cards are dealt from a deck of 52 cards. ​(a) What is the probability that...
Four cards are dealt from a deck of 52 cards. ​(a) What is the probability that the ace of spades is one of the 4 cards​? (b) Suppose one of the 4 cards is chosen at random and found not to be the ace of spades. What is the probability that none of the 4 cards is the ace of​ spades? ​(c) Suppose the experiment in part​ (b) is repeated a total of 10 times​ (replacing the card looked at...
Four cards are drawn at random from a standard deck of 52 cards. a. What’s the...
Four cards are drawn at random from a standard deck of 52 cards. a. What’s the probability that at least one card is a 7? b. What’s the probability that 3 of the 4 cards are the same suit? c. What’s the probability that they are all the same suit?
1. Two cards are drawn from a deck of cards (consisting of 52 cards: 13 cards...
1. Two cards are drawn from a deck of cards (consisting of 52 cards: 13 cards for each of the four suits, Spades (S), Hearts (H), Diamonds (D) and Clubs (C)). Drawing is done with replacement, that is, the first card is drawn, recorded and put back in the deck, then the second card is drawn and recorded. Assuming an outcome is recorded in the order which two cards are drawn, what is the sample space for this (random) phenomenon?...
A standard poker deck of 52 cards has four suits, (symbols C, H, S, and D)...
A standard poker deck of 52 cards has four suits, (symbols C, H, S, and D) and thirteen ranks (symbols A, 2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, and K). Every card in the deck has both a value and a suit.1 A poker hand is any set of 5 cards from the standard poker deck. There are some special hands in poker, and these have ranks (i.e. some are better, some are worse). From best...
Design a c++ program to simulate the BlackJack game. Rules: 1) single deck, 52 cards -both...
Design a c++ program to simulate the BlackJack game. Rules: 1) single deck, 52 cards -both player and dealer are taking cards off the same deck (the same 52 values). 2) display BOTH cards of the players, and ONE card of the computer. 3) Check for blackjack (starting value of 21 for computer or player) -if either side has a blackjack end of the game, next hand of blackjack 4) Computer must hit if 16 or below. 5) Computer must...
Two cards are randomly selected from a deck of 52 playing cards. (a) What is the...
Two cards are randomly selected from a deck of 52 playing cards. (a) What is the probability they constitute a pair (that is, that they are of the same denomination)? (b) What is the conditional probability they constitute a pair given that they are of different suits?
Three cards are drawn from a deck of 52 cards without replacement. (a) What is the...
Three cards are drawn from a deck of 52 cards without replacement. (a) What is the probability that the third card is a spade (♠) given that the first card is a spade? (b) What is the probability that all cards are spades given that at least one of them is a spade? (c) Let Y be the number of black cards drawn. What is the probability that all 3 cards are black given that the first card is a...
Three cards are drawn from a deck of 52 cards without replacement. (a) What is the...
Three cards are drawn from a deck of 52 cards without replacement. (a) What is the probability that the third card is a spade (♠) given that the first card is a spade? (b) What is the probability that all cards are spades given that at least one of them is a spade? (c) Let Y be the number of black cards drawn. What is the probability that all 3 cards are black given that the first card is a...
1. In the game of poker, five cards from a standard deck of 52 cards are...
1. In the game of poker, five cards from a standard deck of 52 cards are dealt to each player. Assume there are four players and the cards are dealt five at a time around the table until all four players have received five cards. a. What is the probability of the first player receiving a royal flush (the ace, king, queen, jack, and 10 of the same suit). b. What is the probability of the second player receiving a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT