Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can someone check to see why my true and false is not working? #include <stdbool

ID: 3940070 • Letter: C

Question

Can someone check to see why my true and false is not working?

#include <stdbool.h>      
#include <stdio.h>
#include <stdlib.h>

#define NUM_RANKS 13
#define NUM_SUITS 4
#define NUM_CARDS 5

int num_in_rank[NUM_RANKS];
int num_in_suit[NUM_SUITS];
bool card_exists[NUM_RANKS][NUM_SUITS];
bool royal, flush, littedog, bigdog, littlecat, bigcat, straight, straight_flush, four, three, full_house;
int pairs, stud;  

void read_cards(void);
void analyze_hand(void);
void print_result(void);

int main(void)
{
while(1)
{
read_cards();
analyze_hand();
print_result();
}
}

void read_cards(void)
{
char ch, rank_ch, suit_ch;
int rank, suit;
bool bad_card;
int cards_read = 0;

for (rank=0; rank<NUM_RANKS; rank++)
{
num_in_rank[rank] = 0;
for (suit=0; suit<NUM_SUITS; suit++)
card_exists[rank][suit] = false;
}

for (suit=0; suit<NUM_SUITS; suit++)
num_in_suit[suit] = 0;

printf("5 Card or 7 Card Stud? (Type 5 or 7): ");
scanf( "%d", &stud);
  
if(stud == 5)
{printf("5 Card Stud will be played. ");}

else if (stud == 7)
{printf("7 Card Stud will be played. ");}

else if (stud == 0)
{exit(EXIT_SUCCESS);}

while (getchar() != ' ');
while (cards_read<stud)
{
bad_card = false;
printf("Enter a card: ");
rank_ch = getchar();
switch (rank_ch)
{
   case '0':exit(EXIT_SUCCESS);
   case '2':rank = 0; break;
   case '3':rank = 1; break;
   case '4':rank = 2; break;
   case '5':rank = 3; break;
   case '6':rank = 4; break;
   case '7':rank = 5; break;
   case '8':rank = 6; break;
   case '9':rank = 7; break;
   case 't':rank = 8; break;
   case 'j':rank = 9; break;
   case 'q':rank = 10; break;
   case 'k':rank = 11; break;
   case 'a':rank = 12; break;
   case 'T':rank = 8; break;
   case 'J':rank = 9; break;
   case 'Q':rank = 10; break;
   case 'K':rank = 11; break;
   case 'A':rank = 12; break;
   default:bad_card = true;
}
suit_ch = getchar();
switch (suit_ch)
{
   case 'c':suit = 0; break;
   case 'd':suit = 1; break;
   case 'h':suit = 2; break;
   case 's':suit = 3; break;
   case 'C':suit = 0; break;
   case 'D':suit = 1; break;
   case 'H':suit = 2; break;
   case 'S':suit = 3; break;
   default:bad_card = true;
}

while ( (ch=getchar()) != ' ' )
   if (ch != ' ')
   bad_card = true;

if (bad_card)
   printf("Bad card; ignored. ");
else if (card_exists[rank][suit])
   printf("Duplicate card; ignored. ");
else
{
   num_in_rank[rank]++;
   num_in_suit[suit]++;
   card_exists[rank][suit] = true;
   cards_read++;
}
}
}

void analyze_hand(void)
{
int num_consec = 0, royal_consec = 0, total = 0, sf_consec = 0;
int rank, suit;
straight_flush = false;
straight = false;
flush = false;
four = false;
three = false;
littledog = false;
bigdog = false;
littlecat = false;
bigcat = false;
royal = false;
pairs = 0;

for (rank=0; rank<NUM_RANKS; rank++)
{
if (num_in_rank[rank] == 4)
   four = true;
if (num_in_rank[rank] == 3)
   three = true;
if (num_in_rank[rank] == 2)
   pairs++;
}
rank = 0;
while (num_in_rank[rank] == 0)
rank++;
for (rank; rank<NUM_RANKS; rank++)
{
total = total + num_in_rank[rank];
if(num_in_rank[rank] == 0 && total < 7 && stud == 7)
{num_consec = 0;}

else
{num_consec++;}
}
if (num_consec >= NUM_CARDS)
{
straight = true;
return;
}
  
for (suit=0; suit<stud; suit++)
if (num_in_suit[suit] == NUM_CARDS)
   flush = true;

if (straight && flush)
{
suit =0;
while (suit<NUM_SUITS)
{
for(rank==NUM_RANKS; rank >=0; rank-- )
{
if (card_exists[rank][suit])
{sf_consec++;}
  
else if (!card_exists[rank][suit])
{sf_consec = 0;}
}
}
if (sf_consec >= NUM_CARDS)
straight_flush= true;
}
suit=0;
while (suit<NUM_SUITS)
{
for (rank=NUM_RANKS; rank>7; rank--)
{
if(card_exists[suit][rank])
{royal_consec++;}
}
suit++;
}
if (royal_consec==NUM_CARDS)
royal = true;
}
void print_result(void)
{
if (royal)
printf("Royal Flush");
else if (straight_flush)
printf("Straight Flush");
else if (four)
printf("Four of a Kind");
else if (three && pairs == 1)
printf("Full House");
else if (flush)
printf("Flush");
else if (straight)
printf("Straight");
else if (three)
printf("Three of a Kind");
else if (pairs == 2)
printf("Two Pairs");
else if (pairs == 1)
printf("Pair");
else
printf("High Card");
printf(" ");
}

#include #include #include 10 12 13 14 15 16 17 18 #de fine NUM RANKS 13 #de fine NUM SUITS 4 #de fine NUM CARDS 5 int num in rank[NUM RANKS] int num_in suit [NUM SUITS]: bool card exists [NUM RANKS1 [NUM SUITS]: bool royal, flush, littedog, bigdog, littlecat, bigcat, straight, straight flush, four, three, full_house: int pairs, stud; 21 23 24 25 26 27 28 29 30 void read cards (void); void analyze hand (void) void print result (void) int main (void) while (1) Terminal localhost Output poker (Build) ece70k14@ezekiel.engr.csufresno.edu:22 X Copying project files to /home ece70k/ece70k14/.netbeans/remote/ezekiel.engr.csufresno. edu/laptop-mo7gg4eb-Windows-x8664/ at ece70k14@ezekiel.engr.csufresno.edu cd '/home ece70k/ece70k14/.netbeans/remote/ezekiel.engr.csufresno.edu/laptop-mo7qg4eb-Windows-x86_64/C/Users/Mai Shoua Her/Desktop/ECE 70/poker' /usr/bin/gmake -f Makefile CONF-Debug "/usr/bin/gmake" -f nbproject/Makefile-Debug .mk OMAKE= SUBPROJECTS= ·build-conf gmake [11: Entering directory/home/ece70k/ece70k14/.netbe ans/remote/ezekiel.engr.csufresno.edu/laptop-n07gg4eb-Windows-x86-64/C/Users/Mai Shoua Her/Desktop/ECE 70/poker "fusr/bin/gmake"f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux/poker gma ke [21: Entering directory/home/ece70k/ece70k14/.netbeans/remote/ezekiel . engr .csufresno.edu/laptop-n07gg4eb-Windows-x86-64/C/Users/Mai Shoua Her/Desktop/ECE 70/poker mkdir-p bui1d/Debug/GNU-Linux rm -f "build/Debug/GNU-Linux/poker.o.d" gCc poker.: In function 'analyze hand': poker. c : 136 : 3 : error: ' littledog ' undeclared first use in this function) -c-g-MMD-MP ME "build/Debug/GNU-Linux/poker.o.d"-o build/Debug/GNU-Linux/poker.o poker.c littledogfalse poker.c:136:3: note: each undeclared identifier is reported only once for each function it appears in gmake [2]: **[build/Debug/GNU-Linux/poker.ol Error 1 gma ke [21: Leaving directory/home/ece 70k/ece 70 k 14/.netbe ans/remote/ezekiel.eng.csufresno.edu/laptop-mo7gg4eb-Windows-x86-64/C/Users/Mai gmake [1]: **[.build-conf] Error 2 gmake [11: Leaving directory /home/ece70k/ece70k14/.netbe ans/remote/ezekiel.engr .csufresno.edu/laptop-m07qg4eb-Windows-x8664/C/Users/Mai gmake: [.build-impl] Error 2 Shoua Her/Desktop/ ECE 70/poker' Shoua Her/Desktop/ECE 70/poker' BUILD FAILED (exit value 2, total time: 2s)

Explanation / Answer

The following code is running in CodeBlock compiler. (i did some of changes please check in CodeBlock Compiler)

#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#define NUM_RANKS 13
#define NUM_SUITS 4
#define NUM_CARDS 5
int num_in_rank[NUM_RANKS];
int num_in_suit[NUM_SUITS];
bool card_exists[NUM_RANKS][NUM_SUITS];
bool royal, flush, littedog, bigdog, littlecat, bigcat, straight, straight_flush, four, three, full_house;
int pairs, stud;
void read_cards(void);
void analyze_hand(void);
void print_result(void);
int main(void)
{
while(1)
{
read_cards();
analyze_hand();
print_result();
}
}
void read_cards(void)
{
char ch, rank_ch, suit_ch;
int rank, suit;
bool bad_card;
int cards_read = 0;
for (rank=0; rank<NUM_RANKS; rank++)
{
num_in_rank[rank] = 0;
for (suit=0; suit<NUM_SUITS; suit++)
card_exists[rank][suit] = false;
}
for (suit=0; suit<NUM_SUITS; suit++)
num_in_suit[suit] = 0;
printf("5 Card or 7 Card Stud? (Type 5 or 7): ");
scanf( "%d", &stud);

if(stud == 5)
{printf("5 Card Stud will be played. ");}
else if (stud == 7)
{printf("7 Card Stud will be played. ");}
else if (stud == 0)
{exit(EXIT_SUCCESS);}
while (getchar() != ' ');
while (cards_read<stud)
{
bad_card = false;
printf("Enter a card: ");
rank_ch = getchar();
switch (rank_ch)
{
case '0':exit(EXIT_SUCCESS);
case '2':rank = 0; break;
case '3':rank = 1; break;
case '4':rank = 2; break;
case '5':rank = 3; break;
case '6':rank = 4; break;
case '7':rank = 5; break;
case '8':rank = 6; break;
case '9':rank = 7; break;
case 't':rank = 8; break;
case 'j':rank = 9; break;
case 'q':rank = 10; break;
case 'k':rank = 11; break;
case 'a':rank = 12; break;
case 'T':rank = 8; break;
case 'J':rank = 9; break;
case 'Q':rank = 10; break;
case 'K':rank = 11; break;
case 'A':rank = 12; break;
default:bad_card = true;
}
suit_ch = getchar();
switch (suit_ch)
{
case 'c':suit = 0; break;
case 'd':suit = 1; break;
case 'h':suit = 2; break;
case 's':suit = 3; break;
case 'C':suit = 0; break;
case 'D':suit = 1; break;
case 'H':suit = 2; break;
case 'S':suit = 3; break;
default:bad_card = true;
}
while ( (ch=getchar()) != ' ' )
if (ch != ' ')
bad_card = true;
if (bad_card)
printf("Bad card; ignored. ");
else if (card_exists[rank][suit])
printf("Duplicate card; ignored. ");
else
{
num_in_rank[rank]++;
num_in_suit[suit]++;
card_exists[rank][suit] = true;
cards_read++;
}
}
}
void analyze_hand(void)
{
int num_consec = 0, royal_consec = 0, total = 0, sf_consec = 0;
int rank, suit;
straight_flush = false;
straight = false;
flush = false;
four = false;
three = false;
bool littledog = false;
bigdog = false;
littlecat = false;
bigcat = false;
royal = false;
pairs = 0;
for (rank=0; rank<NUM_RANKS; rank++)
{
if (num_in_rank[rank] == 4)
four = true;
if (num_in_rank[rank] == 3)
three = true;
if (num_in_rank[rank] == 2)
pairs++;
}
rank = 0;
while (num_in_rank[rank] == 0)
rank++;
for (rank; rank<NUM_RANKS; rank++)
{
total = total + num_in_rank[rank];
if(num_in_rank[rank] == 0 && total < 7 && stud == 7)
{num_consec = 0;}
else
{num_consec++;}
}
if (num_consec >= NUM_CARDS)
{
straight = true;
return;
}

for (suit=0; suit<stud; suit++)
if (num_in_suit[suit] == NUM_CARDS)
flush = true;
if (straight && flush)
{
suit =0;
while (suit<NUM_SUITS)
{
for(rank==NUM_RANKS; rank >=0; rank-- )
{
if (card_exists[rank][suit])
{sf_consec++;}

else if (!card_exists[rank][suit])
{sf_consec = 0;}
}
}
if (sf_consec >= NUM_CARDS)
straight_flush= true;
}
suit=0;
while (suit<NUM_SUITS)
{
for (rank=NUM_RANKS; rank>7; rank--)
{
if(card_exists[suit][rank])
{royal_consec++;}
}
suit++;
}
if (royal_consec==NUM_CARDS)
royal = true;
}
void print_result(void)
{
if (royal)
printf("Royal Flush");
else if (straight_flush)
printf("Straight Flush");
else if (four)
printf("Four of a Kind");
else if (three && pairs == 1)
printf("Full House");
else if (flush)
printf("Flush");
else if (straight)
printf("Straight");
else if (three)
printf("Three of a Kind");
else if (pairs == 2)
printf("Two Pairs");
else if (pairs == 1)
printf("Pair");
else
printf("High Card");
printf(" ");
}

---------------------------------------------------------------------------------------------

If you have any query or still have issue, please feel free to ask.

Thanks a lot.