Question: C++ help with card trick program My program is working. However, I need the code to be modified that if a user inputs n, it

C++ help with card trick program

My program is working. However, I need the code to be modified that if a user inputs "n", it does not show the deck of card and ends the program. It is bolded below the program where the modification needs to be:

#include

#include

#include

#include

using namespace std;

// Function prototypes

void BuildDeck( int deck[], const int size );

void PrintDeck( int deck[], const int size );

void Deal( int deck[], int play[][3] );

void PickUp( int deck[], int play[][3], int column );

void SecretCard( int deck[] );

void PrintCard( int card );

string Cap_Name( string word );

int main(void)

{

/* declare and initialize variables */

int column = 0, i = 0;

string name;

char playAgain;

char seeDeck;

/* Declare a 52 element array of integers to be used as the deck of cards */

int deck[52] = {0};

/* Declare a 7 by 3 array to receive the cards dealt to play the trick */

int play[7][3] = {0};

/* Generate a random seed for the random number generator. */

srand(time(0));

/* Opening message. Ask the player for his/her name */

cout

cin >> name;

/* Capitalize the first letter of the person's name. */

name = Cap_Name(name);

cout

do

{

/* Build the deck */

BuildDeck(deck, 52);

/* Ask if the player wants to see the entire deck. If so, print it out. */

cout

cin >> seeDeck;

if (seeDeck=='y')

{

cout

PrintDeck(deck, 52);

}

cout

/* Begin the card trick loop */

for(i = 0; i

{

/* Begin the trick by calling the function to deal out the first 21 cards */

Deal(deck, play);

/* Include error checking for entering which column */

do

{

/* Ask the player to pick a card and identify the column where the card is */

cout

cin >> column;

} while(column 2);

/* Pick up the cards, by column, with the selected column second */

PickUp(deck, play, column);

}

/* Display the top ten cards, then reveal the secret card */

SecretCard(deck);

/* if the player wants to play again */

cout

cin >> playAgain;

} while(playAgain == 'y');

/* Exiting message */

cout

return 0;

}

void BuildDeck( int deck[], const int size)

{

int used[52] = {0};

int card = 0, i = 0;

for(i = 0; i

{

do

{

/* generate a random number between 0 and 51 */

card = rand() % 52;

/* Check the used array at the position of the card.

If 0, add the card and set the used location to 1. If 1, generate another number */

} while(used[card] == 1);

used[card]++;

deck[i] = card;

}

return;

}

void PrintDeck( int deck[], const int size )

{

int i;

/* Print out each card in the deck */

for (i = 0; i

{

if(i%3 == 0)

cout

PrintCard(deck[i]);

}

}

void Deal( int deck[], int play[][3] )

{

int row = 0, col = 0, card = 0;

for (row = 0; row

{

play[row][col] = deck[card];

for (col = 0; col

{

play[row][col] = deck[card];

card++;

}

}

/* deal cards by passing addresses of cardvalues from

the deck array to the play array */

cout

cout

cout

for(int row = 0; row

{

for(int col = 0; col

{

//cout.width(5);

PrintCard(play[row][col]);

}

cout

}

return;

}

void PrintCard( int card ) // WORKS

{

int rank = 0;

int suit = 0;

rank = card % 13, suit = (card - rank) / 13;

// Determine the rank of the card and print it out i.e. Queen

if (rank == 0)

cout

else if (rank == 9)

cout

else if (rank == 10)

cout

else if (rank == 11)

cout

else if (rank == 12)

cout

else

cout

cout

// Determine the suit of the card and print it out i.e. of Clubs

if (suit == 0)

cout

else if (suit == 1)

cout

else if (suit == 2)

cout

else

cout

return;

}

void PickUp( int deck[], int play[][3], int column )

{

int card = 0, row = 0;

for (row =0 ; row

{

int pickupColumn = (column + row + 2) % 3;

for(int cardInColumn = 0; cardInColumn

{

deck[card++] = play[cardInColumn][pickupColumn];

}

}

return;

}

void SecretCard( int deck[] )

{

int card = 0;

cout

for(card = 0; card

{

cout.width(5);

PrintCard(deck[card]);

cout

}

cout

PrintCard(deck[card]);

cout

return;

}

// Capitalize the first letter in a string

string Cap_Name(string word)

{

if (!word.empty())

{

word[0] = toupper(word[0]);

}

return word;

}

C++ help with card trick program My program is working. However, I

Whenever "n" is entered, I need to the program to say something like " ok, come play again another time", instead of continuing with the game.

input Hello, I am a computer program that is so smart I can even perform a card trick. Here's how o begin the card trick type in your name: john hank you John k John, first things first. Do you want to see what he deck of cards looks like (y)? r ohn pick a card and remember it... Column 0 Column 1 Column 2 1 of Hearts 6 of Clubs Queen of Diamonds Queen of Hearts 6 of Hearts 5 of Spades Ace of Spades 5 of Clubs 8 of Spades 8 of Hearts 10 of Spades 2 of Clubs 4 of Hearts 4 of Clubs Jack of Diamonds Jack of Clubs King of Clubs 6 of Diamonds 3 of Hearts 7 of Hearts 10 of Clubs Which column is your card in (0, 1, or 2)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!