Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Question I am having problems with the compiler saying I have some undeclared identifiers and identifier not found. Below is my code. #include #include

C++ Question I am having problems with the compiler saying I have some undeclared identifiers and identifier not found. Below is my code.

#include #include

using namespace std;

enum suits {CLUBS, DIAMONDS, HEARTS, SPADES}; enum cardValues {TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING, ACE};

struct { suits suit; cardValues card; };

cards deck[52]; cards card1, card2;

void createDeck(cards card[]) {

for (int i = 0; i < 4; i++) { for (int j = 0; j < 13; j++) { card[13 * i + j].suit = (suits)i; card[13 * i + j].card = (cardValues)j;

} } }

void printCards(cards card) {

switch (card.card) {

case TWO: cout << "TWO";

case THREE: cout << "THREE";

case FOUR: cout << "FOUR";

case FIVE: cout << "FIVE";

case SIX: cout << "SIX";

case SEVEN: cout << "SEVEN";

case EIGHT: cout << "EIGHT";

case NINE: cout << "NINE";

case TEN: cout << "TEN";

case JACK: cout << "JACK";

case QUEEN: cout << "QUEEN";

case KING: cout << "KING";

case ACE: cout << "ACE";

break; }

cout << " of ";

switch (card.suit) { case CLUBS: cout << "CLUBS"; break;

case DIAMONDS: cout << "DIAMONDS"; break;

case HEARTS: cout << "HEARTS"; break;

case SPADES: cout << "SPADES"; break; }

cout << " "; }

void printDeck(cards card[]) {

for (int i = 0; i < 52; i++) { printCard(card[i]); } }

void deal(cards deck[], cards &card) { int randomCard = (rand() % 52) + 1; card = deck[randomCard]; }

void winner(cards card1, cards card2); { for (int i = 0; i < 52; i++) { if (card1.suit == deck[i].suit && card1.card == deck[i].card) { cout << " Card 2 wins"; printCard(card2); return; } } }

int main() { createDeck(deck); printDeck(deck);

deal(deck, card1); cout << " Card 1 = "; printCard(card1);

deal(deck, card2); cout << " Card 2 = "; printCard(card2);

cout << " And the winner is "; winner(card1, card2);

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions