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[], char *faces[], int
deck[][FACES]);
void analyzeHand(int suitsInHand[], int facesInHand[]);
void printResults(int suitsInHand[SUITS], int facesInHand[FACES],
int *pointValue);
typedef int bool;
bool straight, flush, four, three;
int pairs; /* can be 0, 1, or 2 */
int main() {
char *suits[4] = {"Hearts", "Diamonds", "Spades",
"Clubs"};
char *faces[13] = {"Two", "Three", "Four", "Five", "Six", "Seven",
"Eight", "Nine", "Ten", "Jack", "Queen", "King", "Ace" };
int deck[4][13] = { AVAILABLE };
int i;
int suitsInHand[SUITS], facesInHand[FACES];
srand(time(NULL));
for(i = 0; i < 1; i++) {
printf("Player1 \n");
dealAHand(suits, faces, deck);
}
for(i = 1; i < 2; i++) {
printf("Player2 \n");
dealAHand(suits, faces, deck);
}
system("pause");
}
void dealAHand(char *suits[], char *faces[], int
deck[][FACES]){
int i;
for(i = 0; i < 5; i++)
dealACard(suits, faces, deck);
printf("\n");
}
void dealACard(char *suits[], char *faces[], int deck[][FACES]){
int suitIndex, faceIndex;
suitIndex = rand() % 4;
faceIndex = rand() % 13;
while (deck[suitIndex][faceIndex] == TAKEN){
suitIndex = rand() % 4;
faceIndex = rand() % 13;
}
deck[suitIndex][faceIndex] = TAKEN;
printf("%s of %s \n", faces[faceIndex], suits[suitIndex]);
}
void analyzeHand(int suitsInHand[SUITS], int facesInHand[FACES]){
int num_consec = 0;
int rank, suit;
straight = FALSE;
flush = FALSE;
four = FALSE;
three = FALSE;
pairs = 0;
/* check for flush */
for (suit = 0; suit < SUITS; suit++)
if (suitsInHand[suit] == 5)
flush = TRUE;
/* check for straight */
rank = 0;
while (facesInHand[rank] == 0)
rank++;
for (rank = 0; rank < FACES && facesInHand[rank];
rank++)
num_consec++;
if (num_consec == 5) {
straight = TRUE;
return;
}
/* check for 4-of-a-kind, 3-of-a-kind, and pairs */
for (rank = 0; rank < FACES; rank++) {
if (facesInHand[rank] == 4)
four = TRUE;
if (facesInHand[rank] == 3)
three = TRUE;
if (facesInHand[rank] == 2)
pairs++;
}
void printResults(int suitsInHand[SUITS], int
facesInHand[FACES], int *pointValue) {
void analyzeHand(suitsInHand, facesInHand);
if (straight && flush) {
printf("Straight flush\n\n");
*pointValue = 9;
}
else if (four) {
printf("Four of a kind\n\n");
*pointValue = 8;
}
else if (three && pairs == 1) {
printf("Full house\n\n");
*pointValue = 7;
}
else if (flush) {
printf("Flush\n\n");
*pointValue = 6;
}
else if (straight) {
printf("Straight\n\n");
*pointValue = 5;
}
else if (three) {
printf("Three of a kind\n\n");
*pointValue = 4;
}
else if (pairs == 2) {
printf("Two pairs\n\n");
*pointValue = 3;
}
else if (pairs == 1) {
printf("Pair\n\n");
*pointValue = 2;
points = *pointValue;
}
else{
printf("High card\n\n");
*pointValue = 1;
points = *pointValue;
}
return points = *pointValue;
}
Note: Removed all the errors and now its compiling. I have highlighted the changed code and also commented the reason for error.
#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[], char *faces[], int
deck[][FACES]);
void analyzeHand(int suitsInHand[], int facesInHand[]);
void printResults(int suitsInHand[SUITS], int facesInHand[FACES],
int *pointValue);
typedef int boolean; //bool is a data type thats why
throwing error so changed it to boolean
boolean straight, flush, four, three;
int pairs; /* can be 0, 1, or 2 */
int main() {
char *suits[4] = {"Hearts", "Diamonds", "Spades",
"Clubs"};
char *faces[13] = {"Two", "Three", "Four", "Five",
"Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King",
"Ace" };
int deck[4][13] = { AVAILABLE };
int i;
int suitsInHand[SUITS], facesInHand[FACES];
srand(time(NULL));
for(i = 0; i < 1; i++) {
printf("Player1 \n");
dealAHand(suits, faces,
deck);
}
for(i = 1; i < 2; i++) {
printf("Player2 \n");
dealAHand(suits, faces,
deck);
}
system("pause");
}
void dealAHand(char *suits[], char *faces[], int
deck[][FACES]){
int i;
for(i = 0; i < 5; i++)
dealACard(suits, faces,
deck);
printf("\n");
}
void dealACard(char *suits[], char *faces[], int deck[][FACES]){
int suitIndex, faceIndex;
suitIndex = rand() % 4;
faceIndex = rand() % 13;
while (deck[suitIndex][faceIndex] == TAKEN){
suitIndex = rand() % 4;
faceIndex = rand() % 13;
}
deck[suitIndex][faceIndex] = TAKEN;
printf("%s of %s \n", faces[faceIndex], suits[suitIndex]);
}
void analyzeHand(int suitsInHand[SUITS], int facesInHand[FACES]){
int num_consec = 0;
int rank, suit;
straight = FALSE;
flush = FALSE;
four = FALSE;
three = FALSE;
pairs = 0;
/* check for flush */
for (suit = 0; suit < SUITS; suit++)
if (suitsInHand[suit] == 5)
flush =
TRUE;
/* check for straight */
rank = 0;
while (facesInHand[rank] == 0)
rank++;
for (rank = 0; rank < FACES &&
facesInHand[rank]; rank++)
num_consec++;
if (num_consec == 5) {
straight = TRUE;
return;
}
/* check for 4-of-a-kind, 3-of-a-kind, and pairs
*/
for (rank = 0; rank < FACES; rank++) {
if(facesInHand[rank] == 4)
four =
TRUE;
if(facesInHand[rank] == 3)
three =
TRUE;
if(facesInHand[rank] == 2)
pairs++;
}
} //function was not closed
void printResults(int suitsInHand[SUITS], int
facesInHand[FACES], int *pointValue) {
analyzeHand(suitsInHand,
facesInHand); //void was extra so removed it
if (straight && flush)
{
printf("Straight
flush\n\n");
*pointValue = 9;
}
else if (four) {
printf("Four of
a kind\n\n");
*pointValue =
8;
}
else if (three && pairs ==
1) {
printf("Full
house\n\n");
*pointValue =
7;
}
else if (flush) {
printf("Flush\n\n");
*pointValue =
6;
}
else if (straight) {
printf("Straight\n\n");
*pointValue =
5;
}
else if (three) {
printf("Three of
a kind\n\n");
*pointValue =
4;
}
else if (pairs == 2) {
printf("Two
pairs\n\n");
*pointValue =
3;
}
else if (pairs == 1) {
printf("Pair\n\n");
*pointValue =
2;
//points =
*pointValue;
}
else{
printf("High
card\n\n");
*pointValue =
1;
//points
= *pointValue; //points was undeclared, also it is not needed as
pointValue is a pointer
}
//return points =
*pointValue; //cant return value in a void function
}
I'm writing code for a poker game and I'm not sure where I'm going wrong with...
(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...
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 ]...
1. Find the probabilities of Poker hands not covered in class. Recall in a Poker game, 5 cards are drawn uniformly at random from a deck of 52 cards. Each deck has 13 denominations ({A, 2, 3, . . . , 10, J Q, K)) and 4 suits (4,◇,0,6 ). In what follows consecutive denominations are But (J,Q,K, A, 21 is not considered consecutive. Find the probabilities of a. Straight Flush (5 cards of consecutive denomination, all of the same...
A standard poker deck of 52 cards has four suits, (symbols C, H, S, and D) and thirteen ranks (symbols A, 2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, and K). Every card in the deck has both a value and a suit.1 A poker hand is any set of 5 cards from the standard poker deck. There are some special hands in poker, and these have ranks (i.e. some are better, some are worse). From best...
Need help writing this program! Thanks in advance. Project4 Specifications: Determine Poker Hand A poker hand can be stored in a two-dimensional array. The statement: Dim aryintCards(4,14) as Integer (See AryCardExample.xlsx excel spreadsheet) declares an array which the first subscript 1-4 are the four suits and the second subscript ranges over the card denominations: 1-14: Ace, 2, ..., 10, Jack, Queen, King, Ace (repeated). First subscript of 0 is Total of each denomination. Second subscript of 0 is Total of...
C Programming The following code creates a deck of cards, shuffles it, and deals to players. This program receives command line input [1-13] for number of players and command line input [1-13] for number of cards. Please modify this code to deal cards in a poker game. Command line input must accept [2-10] players and [5] cards only per player. Please validate input. Then, display the sorted hands, and then display the sorted hands - labeling each hand with its...
I'm currently writing a program based on stub poker and trying to deal cards to the players, show their hands, and determine the winner, and lastly ask them to if they want to play another hand. I'm probably going to have to write a method to compare hands but i really need to just deal the cards and store in their hands Any help or suggestions? Here are my current classes. public class PlayingCard { private final Suit suit;...
Need help with shuffle function and give 8 cards to user and computer from shuffle deck? #include <stdio.h> #include <stdbool.h> #include <string.h> #include <stdlib.h> #include <math.h> #include <time.h> typedef struct card_s{ char suit; int face; struct card_s *listp; } card; void card_create(card* thisNode, char cardSuit, int cardFace, card* nextLoc) { thisNode->suit = cardSuit; thisNode->face = cardFace; thisNode->listp = nextLoc; return; } void card_insertAfter(card* thisNode, card* newNode) { card* tmpNext = NULL; ...
Question: For the picture writing question, if the question says that the picture length (height) and width are multiples of 5, then be prepared (for example) to handle a situation where you are being asked to blacken the fourth (vertical) strip from the left. Code: #include #include #include #include #define BUFFER_SIZE 70 #define TRUE 1 #define FALSE 0 int** img; int numRows; int numCols; int maxVal; FILE* fo1; void addtopixels(int** imgtemp, int value); void writeoutpic(char* fileName, int** imgtemp); int** readpic(char*...