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

This is what I have so far but the program does not display the correct number o

ID: 3561964 • Letter: T

Question

This is what I have so far but the program does not display the correct number or suit for the cards. The program also does not do the totaling of point correctly. Numbered cards should equal their value, face cards should eqaul 10 and ace should be 11 points. Anyone who can help me finish this would be great!

#include <stdio.h>
#include <stdlib.h>
#define SIZE 52


void create_deck (int[]);
void shuffle_deck(int[]);
void display_card(int);
void fill_deck   (int[]);
int popCard      (int,int[]);
int findScore    (int[]);
int choice = 1;

//function to create the deck of cards
void create_deck(int deck[])

    {
        int i;
        for (i=0; i < SIZE ; i++);
        deck[i] = i + 1;
   return;
        }

    //function to shuffle deck
    void shuffle_deck(int deck[])
    {
   int i;     //counter
   int j;     //variable to hold random value between 0 - 51
   int temp; //define temporary structure for swapping Cards


   //loop through deck randomly swapping Cards
   for ( i = 0; i <= SIZE; i++ )
     {
      j = rand() % SIZE;
      temp = deck[ i ];
      deck[ i ] = deck[ j ];
      deck[ j ] = temp;
     }
    }

//function to display the card
void display_card(int card)

{
   int face, suit;
   face = card % 13;
   if(face < 10)
   {
      printf("%d ", card+1);
   }
   else if(card == 10)
   {
      printf("Jack");
   }
   else if(card == 11)
   {
      printf("Queen");
   }
   else if(card == 12)
   {
      printf("King");
   }
   suit = ((card-1) / 13);
   if(suit == 0)
   {
      printf("Diamonds");
   }
   else if(suit == 1)
   {
      printf("Hearts");
   }
   else if(suit == 2)
   {
      printf("Clubs");
   }
   else if(suit == 3)
   {
      printf("Spades");
   }
   else if(face == 0)
   {
      printf("Ace");
   }

    return;
}
int popCard(int j, int deck[])
{
    int i;
    int card = deck[0];
    for(i=0; i < j; i++)
    {
        deck[i]= deck[i+1];
    }
    j--;
    return card;
}
int findScore(int deck[])
   {

   int i, n, sum, card, face, points;
   for (i=0; i<n; i++)
   {
      sum =0;
      card = deck[i];
      face = card % 13;
      if (face == 0)
      {
         points = 11;
      }
   else if (face < 10)
      {
        points = face + 1;
      }
   else if (face < 13)
      {
        points = 10;
      }
    sum += points;
}
   return sum;
}
int main()
{
    int deck[SIZE], s;

    //explaning game to user
    printf("Welcome to Card Counter! ");
    printf("This is a game where you and the computer will each");
    printf("get dealt 5 cards and whoevers card's sum to the highest");
    printf("number will be declared the winner. ");
    printf("Would you like to play Card Counter:   (1 for yes or 2 for no)? ");
    scanf("%d", &choice);

    //asking user if they want to play
    while(choice == 1)
    {

        create_deck(deck); //run the function to make the deck

        //ask user to shuffle the cards
        printf("Press '1' to shuffle the deck ");
        scanf("%d", &s);
        shuffle_deck(deck);

        int popCard(deck); //assign cards to player
        display_card(deck); //show the player what cards they have
        int findScore(int deck[]); //find and report the score back to the player

            //Ask if they would like to play
            printf("Would you like to play Card Counter:   (1 for yes or 2 for no)? ");
            scanf("%d", &choice);
    }
        if (choice == 2);

        {
            printf("Thanks for playing!");
            exit;
        }

return 0;
}

Explanation / Answer

#ifndef DECK_H_ #define DECK_H_ #define DECK_SIZE 52 /* * Creates a structure representing a Deck of Cards. The 'cards' member is * an array of cards within the deck, and the 'iterator' member is the location * of the last accessed card. */ struct Deck { struct Card* cards; int iterator; int number_of_decks; }; /* * Creates a new Deck of cards. The 'number_of_decks' parameter dictates how * many 52-card decks will be generated in the Deck. */ struct Deck create_deck(const int number_of_decks); /* Shuffles the cards within the Deck. */ void shuffle_deck(struct Deck* deck); /* * Returns the next Card structure in the Deck, or NULL if the iterator has * reached the end of the Deck. */ struct Card* deck_next_card(struct Deck* deck); #endif /* DECK_H_ */

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote