Can someone help me get this C program to work? I am trying to get a 2d array to work correctly.
/* Deals a random hand of cards */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define TRUE 1
#define FALSE 0
#define BOOL int
#define NUM_SUITS 4
#define NUM_RANKS 13
int main()
{
BOOL in_hand[NUM_SUITS][NUM_RANKS] = {FALSE};
int num_cards = 13, rank, suit;
const char rank_code[ 13 ][ 10 ] =
{"Ace","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Jack","Queen","King"};
const char suit_code[ 4 ] [ 10 ] = { "Clubs", "Diamonds", "Hearts",
"Spades" };
srand( time(NULL));
printf("Your hand :");
while(num_cards > 0) {
suit = rand() % NUM_SUITS;
rank = rand() % NUM_RANKS;
if (!in_hand[suit][rank]) {
in_hand[suit][rank] = TRUE;
num_cards--;
printf(" %c%c", rank_code[rank], suit_code[suit]);
}
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define TRUE 1
#define FALSE 0
#define BOOL int
#define NUM_SUITS 4
#define NUM_RANKS 13
int main()
{
BOOL in_hand[NUM_SUITS][NUM_RANKS] = {FALSE};
int num_cards = 13, rank, suit;
const char rank_code[ 13 ][ 10 ] =
{"Ace","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Jack","Queen","King"};
const char suit_code[ 4 ] [ 10 ] = { "Clubs", "Diamonds", "Hearts",
"Spades" };
srand( time(NULL));
printf("Your hand :");
while(num_cards > 0) {
suit = rand() % NUM_SUITS;
rank = rand() % NUM_RANKS;
if (!in_hand[suit][rank]) {
in_hand[suit][rank] = TRUE;
num_cards--;
// %s should use not %c as it has strings to print
printf(" %s%s", rank_code[rank], suit_code[suit]);
}
}
return 0;
}

Note : Please comment below if you have concerns. I am here to help you
If you like my answer please rate and help me it is very Imp for me
Can someone help me get this C program to work? I am trying to get a...
I'm writing code for a poker game and I'm not sure where I'm going wrong with it. My compiler is sending back errors for lines (typedef int bool)(the two char* declarations) and the two functions before my if else statement (approx lines 109). #include <stdio.h> #include <stdlib.h> #include <time.h> #define SUITS 4 #define FACES 13 #define AVAILABLE 0 #define TAKEN 1 #define SIZE 5 #define TRUE 1 #define FALSE 0 void dealACard(char *suits[], char *faces[], int deck[][FACES]); void dealAHand(char *suits[],...
(Card Shuffling and Dealing) Modify the program below so that the card-dealing function deals a five-card poker hand. Then write the following additional functions: a) Determine whether the hand contains two pairs b) Determine whether the hand contains a full house (i.e., three of a kind with pair). c) Determinewhetherthehandcontainsastraight flush (i.e.,fivecardsofconsecutivefacevalues). d) Determine whether the hand contains a flush (i.e., five of the same suit) #include <stdio.h> #include <stdlib.h> #include <time.h> #define SUITS 4 #define FACES 13 #define CARDS...
7.12 (Card Shuffling and Dealing) Modify the program in Fig. 7.24 so that the card-dealing function deals a five-card poker hand. Then write the following additional functions: a) Determine whether the hand contains a pair. b) Determinewhetherthehandcontainstwopairs. c) Determine whether the hand contains three of a kind (e.g., three jacks). d) Determinewhetherthehandcontainsfourofakind(e.g.,fouraces). e) Determine whether the hand contains a flush (i.e., all five cards of the same suit). f) Determine whether the hand contains a straight (i.e., five cards of...
//main.cpp
#include <iostream>
#include <iomanip>
#include "deck-of-cards.hpp"
void RunAllTests() {
int count;
std::cin >> count;
DeckOfCards myDeckOfCards;
for (int i = 0; myDeckOfCards.moreCards() && i < count;
++i) {
std::cout << std::left << std::setw(19)
<< myDeckOfCards.dealCard().toString();
if (i % 4 == 3)
std::cout << std::endl;
}
}
int main() {
RunAllTests();
return 0;
}
//card.hpp
#ifndef CARD_HPP_
#define CARD_HPP_
#include <string>
class Card {
public:
static const int totalFaces = 13;
static const int totalSuits = 4;
Card(int cardFace, int...
C++
Your solution should for this assignment should consist of five (5) files: Card.h (class specification file) Card.cpp (class implementation file) DeckOfCards.h (class specification file) DeckOfCards.cpp (class implementation file) 200_assign6.cpp (application program) NU eelLS Seven UT Diamonds Nine of Hearts Six of Diamonds For your sixth programming assignment you will be writing a program to shuffle and deal a deck of cards. The program should consist of class Card, class DeckOfCards and an application program. Class Card should provide: a....
Write a struct to represent a playing card. Playing cards have the following features: They have a suit. This suit can be one of the following: clubs, diamonds, hearts, spades They have a rank. Valid ranks are any number between 2 and 10 (inclusive of 2 and 10), plus ace, jack, queen, and king. Define two enums (Suit and Rank) to represent suits and ranks. Write a short main function to generate a random card, and then print the card's...
I wrote a card shuffle program and I am trying to see how I can add a sorting function to the program to sort the players hands before printing them. How would I do this? #include <iostream> #include <iomanip> #include <vector> #include <algorithm> using namespace std; void printHand(int []); void deal(vector<int> &, int[], int[], int[], int[]); void unwrapDeck(vector<int> &deck) { for(int i=0; i<=51; i++) deck.push_back(i); } void shuffleDeck(vector<int> &deck) { //Status of cards before shuffling cout << "Before shuffling: "...
I've created a Card class and I'm asked to implement a class called DeckOfCards that stores 52 objects of the Card class. It says to include methods to shuffle the deck, deal a card, and report the number of cards left in the deck, and a toString to show the contents of the deck. The shuffle methods should assume a full deck. I also need to create a separate driver class that first outputs the populated deck to prove it...
QUIZ 9 QUESTION 1 An enumeration contains enumerators that represent a. the functions for the enumeration b. the constants for the enumeration c. the operators for the enumeration d. the variables for the enumeration 1 points QUESTION 2 Which of the following problems is not a problem with using unscoped enumerations? a. The code for using them is more complex. b. They allow you to accidentally convert an enumerator to an integer type. c. They can lead to name...
HELP NEED!! Can some modified the program Below in C++ So that it can do what the Problem below asked it today???? #include <iostream> #include <stdlib.h> #include <string> #include <time.h> /* time */ #include <sstream> // for ostringstream using namespace std; // PlayingCard class class PlayingCard{ int numRank; int numSuit; string rank; string suit; public: PlayingCard(); PlayingCard(int numRank,int numSuit); void setRankString(); void setSuitString(); void setRank(int numRank); void setSuit(int numSuit); string getRank(); string getSuit(); int getRankNum(); int getSuitNum(); string getCard(); };...