Programming Project: Pick a Card Before beginning this project, make sureto comp
ID: 3785751 • Letter: P
Question
Programming Project: Pick a Card Before beginning this project, make sureto completely read through the instructions first. A flowchart is provided to you as reference of how the program should flow. write the Pseudocode inthe header comments, as this will be a part of the grade. write a program that simulates picking a card from a deck of 52 cards. Your program should display the rank (Ace, 2, 3, 4,5, 6, 7,8, 9, 10, Jack, Queen, King) and suit (Clubs, Diamonds, Hearts, spades) ofthe card, Make sure to use random numbers! Hint: The algorithm to generate a random number between a range is: int and Num (int) (Math random() (MAX MIN) MIN The flowchart is shown below.Explanation / Answer
You have not specified language of Program. I am using basic c++ language to design complete program.
#include <stdio.h>
#include<stdlib.h>
#include <time.h>
int generate_random_rank()
{
int start_lim=1; // Starting Limit
int end_lim=10; // Ending limit
srand ( time(NULL) ); // Random Seed Generated by using Time
int card=(rand() % end_lim) + start_lim;// Random Number Geneartion in the range of [start_lim,end_lim]
return card; // Return Card Value
}
int generate_random_deck()
{
int start_lim=1; // Starting Limit
int end_lim=4; // Ending Limit
srand ( time(NULL) );// Random Seed Generated by using Time
int deck=(rand() % end_lim) + start_lim; // Random Number Geneartion in the range of [start_lim,end_lim]
return deck; // Return Card Value
}
int main()
{
int rank=0; // Initialize rank as 0
int deck=0; // Initialize Deck as 0
char choice='N'; // Initialize Choice as 'N'
printf("Would you like to pick a card (Y/N): ");
fflush(stdin);
scanf("%c",&choice); // Take a Input for choice
while(choice=='y' || choice=='Y') // Check whether choice is true or False
{
rank=generate_random_rank(); // Generate a random rank
if(rank==1) // if Rank==1 then ACE
{
printf("ACE");
}
else if(rank>1 && rank<11) // if Rank>1 and Rank<11 then Value
{
printf("%d",rank);
}
else if(rank==11)// if Rank==11 then JACK
{
printf("JACK");
}
else if(rank==12) // if Rank==12 then Queen
{
printf("QUEEN");
}
else if(rank==13)// if Rank==13 then KING
{
printf("KING");
}
printf("--");
deck=generate_random_deck(); // Generate Random Deck
if(deck==1) // Deck==1 Then it is CLUBS
{
printf("CLUBS");
}
if(deck==2) // Deck==2 Then it is DIAMONDS
{
printf("DIAMONDS");
}
if(deck==3) // Deck==1 Then it is Hearts
{
printf("HEARTS");
}
if(deck==4) // Deck==1 Then it is SPADES
{
printf("SPADES");
}
printf(" ");
printf("Would you like to pick another card (Y/N): ");
fflush(stdin);
scanf(" %c",&choice); // Check the choice value
}
}
Output:-
Would you like to pick a card (Y/N): Y
ACE--CLUBS
Would you like to pick another card (Y/N): Y
2--DIAMONDS
Would you like to pick another card (Y/N): Y
3--HEARTS
Would you like to pick another card (Y/N): N
sh-4.2$ main^C
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.