This is in C++ its a project for my class I am working on but I am getting error codes :/ can you help me get this to ru

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

This is in C++ its a project for my class I am working on but I am getting error codes :/ can you help me get this to ru

Post by answerhappygod »

This is in C++ its a project for my class I am working on but Iam getting error codes :/ can you help me get this to run andeducate me if you don't mind <3Attached a picture file of the instructions incase you needed someguidness of what I am trying to accomplish thank you for your time<3
This Is In C Its A Project For My Class I Am Working On But I Am Getting Error Codes Can You Help Me Get This To Ru 1
This Is In C Its A Project For My Class I Am Working On But I Am Getting Error Codes Can You Help Me Get This To Ru 1 (108.53 KiB) Viewed 34 times
#include <iostream>#include <iomanip>using namespace std;
// Function prototypesvoid BuildDeck(int deck[], const int size);void PrintDeck(int deck[], const int size);void PrintCard(int card);void Deal(int deck[], int play[][3]);void PickUp(int deck[], int play[][3], int column);void SecretCard(int deck[]);
int main(void){
/* declare and initialize variables */
int column = 0, i = 0;
int SeeTheDeck = 0;
int PlayAgain = 0;
string name;
/* Declare a 52 element array of integers tobe used as the deck of cards */
int deck[52] = {
0
};
/* Declare a 7 by 3 array to receive thecards dealt to play the trick */
int play[7][3] = {
0
};
/* Generate a random seed for the randomnumber generator. */
srand(time(NULL));
/* Openning message. Ask the player forhis/her name */
cout << "Hello, I am a really trickycomputer program and " << endl <<
"I can even perform a cardtrick. Here's how." << endl <<
"To begin the card tricktype in your name: ";
cin >> name;
/* Capitalize the first letter of theperson's name. */
name[0] = toupper(name[0]);
cout << endl << "Thank you "<< name << endl;
do {
/* Build the deck */
BuildDeck(deck, 52);
/* Ask if the player wantsto see the entire deck. If so, print it out. */
cout << "Ok "<< name << ", first things first. Do you want to seewhat " << endl << "the deck of cards looks like (1 =y/0 = n)? ";
cin >>SeeTheDeck;
if (SeeTheDeck == '1'){
cout<< endl;
PrintDeck(deck, 52);
}
cout << endl<< name << " pick a card and remember it..." <<endl;
/* Begin the card trickloop */
for (i = 0; i < 3; i++){
/*Begin the trick by calling the function to deal out the first 21cards */
Deal(deck, play);
/*Include error checking for entering which column */
do{
/* Ask the player to pick a card andidentify the column where the card is */
cout << endl << "Which columnis your card in (0, 1, or 2)?: ";
cin >> column;
} while(column < 0 || column > 2);
/* Pickup the cards, by column, with the selected column second */
PickUp(deck, play, column);
}
/* Display the top tencards, then reveal the secret card */
SecretCard(deck);
/* if the player wants toplay again */
cout << name<< ", would you like to play again (y =1 /n = 0)? ";
cin >>PlayAgain;
} while (PlayAgain == 1);
/* Exiting message */
cout << endl << endl <<"Thank you for playing the card trick!" << endl;
return 0;}
void BuildDeck(int deck[], const int size){ int used[52] = { 0 }; int card = 0, i = 0;
/* Generate cards until the deck is full ofintegers */ while (i < size) { /* generate a random numberbetween 0 and 51 */ card = rand() % 52;
/* Check the used array atthe position of the card. If 0, add the cardand set the used location to 1. If 1, generate another number*/ if (used[card] == 0) { used[card]= 1; deck =card; i++; } } return;}
void PrintDeck(int deck[], const int size){ const int size) {
int i;
/* Print out each card in the deck */
for (i = 0; i < 51; i++) {
if (i % 3 == 0)
cout<< endl;
PrintCard(deck);
}}
void Deal(int deck[], int play[][3]) {
int row = 0, col = 0, card = 0;
for (row = 0; row < 7; row++) {
play[row][col] =deck[card];
for (col = 0; col < 3;col++) {
play[row][col] = deck[card];
card++;
}
}
/* deal cards by passing addresses ofcardvalues from the deck array to the play array */ cout << endl; cout << " Column 0 Column 1 Column 2"); cout <<"=======================================================" << endl; for (int row = 0; row < 7; row++) {
for (int col = 0; col <3; col++) {
//cout.width(5);
PrintCard(play[row][col]);
}
cout << endl;
}
return;
}
void PrintCard(int card){ int rank = 0; int suit = 0;
rank = card % 13, suit =(card - rank) / 13;
// Determine the rank ofthe card and print it out i.e. Queen
if (rank == 0)
cout<< right << setw(7) << " Ace";
else if (rank == 9)
cout<< right << setw(7) << " 10";
else if (rank == 10)
cout<< right << setw(7) << " Jack";
else if (rank == 11)
cout<< right << setw(7) << " Queen";
else if (rank == 12)
cout<< right << setw(7) << " King";
else
cout<< setw(6) << " " << rank;
cout << " of";
// Determine the suit ofthe card and print it out i.e. of Clubs
if (suit == 0)
cout<< left << setw(10) << " Clubs ";
else if (suit == 1)
cout<< left << setw(10) << " Diamonds ";
else if (suit == 2)
cout<< left << setw(10) << " Hearts ";
else
cout<< left << setw(10) << " Spades ";
return;}
void PickUp(int deck[], int play[][], int column){ int card = 0, row = 0; int first = 0, last = 0; switch (column) { case 0: first = 1; last = 2; break; case 1: first = 0; last = 2; break; case 2: first = 2; last = 1; break; } for (row = 0; row < 7; row ++) { deck[card] =play[row][0]; card++; } for (row = 0; row < 7; row++) { deck[card] =play[row][column]; card++; } for (row = 0; row < 7; row++) { deck[card] =play[row][last]; card++; }
return;}
void SecretCard(int deck[]){ int card = 0;
cout << endl << "Finding secretcard..."; for (card = 0; card < 10; card++) { PrintCard(deck[card]); cout << endl; }
cout << endl << "Your secret cardis: "; PrintCard(deck[card]); cout << endl; return;}
Project 2 - Card Trick Write a program to perform the following the following card trick. The program must deal out the cards in three columns, row by row. Jack of Spades 2 of Spades 4 of Diamonds 8 of Hearts 9 of Clubs Queen of Hearts. 7 of Diamonds King of Spades Ace of Hearts 2 of Spades 3 of Diamonds 10 of Clubs Jack of Hearts Queen of Clubs ===== The program must then prompt the user to pick which column his/her card is in. Your program should then pick up that column second, that is: pick up either remaining column first, the selected column, and then the final column. In the example above, assume that the selected card is the Ace of Hearts. The user would select column 0. Your program should pick up column 1, then column 0, and finally column 2. Then it must redeal the cards, which should look like: Jack of Spades 8 of Hearts King of Spades 3 of Diamonds Queen of Clubs 3 of Spades Jack of Clubs Sample Output of the Trick: Column 0 9 of Clubs 6 of Spades Jack of Hearts 6 of Hearts 8 of Clubs 4 of Hearts 10 of Diamonds Your program should repeat this process twice more (selecting the column, picking up and redealing). Then the program must deal out the first ten cards in the deck and declare the eleventh card as the secret card. ======== Column 0 2 of Spades 9 of Clubs Ace of Hearts 10 of Clubs 7 of Diamonds 10 of Hearts King of Diamonds 9 of Clubs Column 1 7 of Clubs Jack of Clubs 4 of Diamonds Jack of Diamonds King of Clubs. Ace of Clubs 5 of Spades Which column is your card in (0, 1, or 2)?: 1 7 of Clubs 3 of Spades 10 of Hearts 9 of Diamonds Jack of Clubs King of Diamonds 6 of clubs Column 1 6 of Spades 4 of Diamonds Queen of Hearts 2 of Spades Jack of Hearts 7 of Clubs 9 of Diamonds 6 of Clubs Column 2 8 of Hearts King of Spades 8 of Diamonds 8 of Spades 9 of Hearts Ace of Spades 3 of Diamonds Column 2 =========== Jack of Hearts 10 of Diamonds 4 of Diamonds Ace of Clubs King of Spades 9 of Hearts 7 of Clubs Jack of Diamonds 5 of Spades 8 of Diamonds Ace of Spades Which column is your card in (0, 1, or 2)2: 2 Column 0 ====== 6 of Spades Jack of Diamonds Ace of Spades Jack of Clubs 8 of Spades 6 of Hearts Ace of Clubs 8 of Clubs 5 of Spades Jack of Hearts Column 1 King of Clubs 3 of Diamonds 10 of Diamonds King of Spades 8 of Clubs 5 of Spades Jack of Hearts King of Clubs 3 of Diamonds 10 of Diamonds King of Spades Jack of Clubs King of Clubs 8 of Hearts 8 of Spades 3 of Diamonds Which column is your card in (0, 1, or 2)?: 0 Finding secret card... 6 of Spades Jack of Diamonds. Ace of Spades Your secret card is: Jack of Clubs Column 2 7 of Clubs 8 of Diamonds 4 of Hearts 8 of Hearts 9 of Clubs 4 of Diamonds 9 of Hearts Program Requirements Your program must generate its own random deck of cards using the following technique: generate a random integer for each card display a string value for each card ("Ace of Diamonds") use the rand() function to generate integer card values use the srand(time(0)) command (only once at the beginning of the program) to generate a truly random deck once the program has been tested and runs properly. Each value must be converted to the format <rank> of <suit> as done in the example above. Whenever your program displays the cards they must line up as they do above, on the word "of". Your program must deal the cards out by row and pick them up by column (3 times to make it work properly). Your program must ask the player is he/she wants to printout the entire deck before playing. Each card must be printed out formatted as above.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply