Zookal
Zookal

We’d love to hear any feedback or comment from you!

© 2011-2021 Zookal Pty Ltd

View question and answer

From our collection of questions and answers
Engineering · Computer Science
Question details

Im making a card game, im wondering how to compare the cards that the players select to play through the trump hearts array, and to make the player with the lowest array point to "win" the round

#include <stdio.h>

void main() {

   const char *cardNames[53];
   cardNames[1] = "Ace of Hearts";
   cardNames[2] = "2 of Hearts";
   cardNames[3] = "3 of Hearts";
   cardNames[4] = "4 of Hearts";
   cardNames[5] = "5 of Hearts";
   cardNames[6] = "6 of Hearts";
   cardNames[7] = "7 of Hearts";
   cardNames[8] = "8 of Hearts";
   cardNames[9] = "9 of Hearts";
   cardNames[10] = "10 of Hearts";
   cardNames[11] = "Jack of Hearts";
   cardNames[12] = "Queen of Hearts";
   cardNames[13] = "King of Hearts";
   cardNames[14] = "Ace of Diamonds";
   cardNames[15] = "2 of Diamonds";
   cardNames[16] = "3 of Diamonds";
   cardNames[17] = "4 of Diamonds";
   cardNames[18] = "5 of Diamonds";
   cardNames[19] = "6 of Diamonds";
   cardNames[20] = "7 of Diamonds";
   cardNames[21] = "8 of Diamonds";
   cardNames[22] = "9 of Diamonds";
   cardNames[23] = "10 of Diamonds";
   cardNames[24] = "Jack of Diamonds";
   cardNames[25] = "Queen of Diamonds";
   cardNames[26] = "King of Diamonds";
   cardNames[27] = "Ace of Spades";
   cardNames[28] = "2 of Spades";
   cardNames[29] = "3 of Spades";
   cardNames[30] = "4 of Spades";
   cardNames[31] = "5 of Spades";
   cardNames[32] = "6 of Spades";
   cardNames[33] = "7 of Spades";
   cardNames[34] = "8 of Spades";
   cardNames[35] = "9 of Spades";
   cardNames[36] = "10 of Spades";
   cardNames[37] = "Jack of Spades";
   cardNames[38] = "Queen of Spades";
   cardNames[39] = "King of Spades";
   cardNames[40] = "Ace of Clubs";
   cardNames[41] = "2 of Clubs";
   cardNames[42] = "3 of Clubs";
   cardNames[43] = "4 of Clubs";
   cardNames[44] = "5 of Clubs";
   cardNames[45] = "6 of Clubs";
   cardNames[46] = "7 of Clubs";
   cardNames[47] = "8 of Clubs";
   cardNames[48] = "9 of Clubs";
   cardNames[49] = "10 of Clubs";
   cardNames[50] = "Jack of Clubs";
   cardNames[51] = "Queen of Clubs";
   cardNames[52] = "King of Clubs";


   const char *trumpHeart[53];
   trumpHeart[1] = "5 of Hearts";
   trumpHeart[2] = "Jack of Hearts";
   trumpHeart[3] = "Ace of Hearts";
   trumpHeart[4] = "King of Hearts";
   trumpHeart[5] = "Queen of Hearts";
   trumpHeart[6] = "10 of Hearts";
   trumpHeart[7] = "9 of Hearts";
   trumpHeart[8] = "8 of Hearts";
   trumpHeart[9] = "7 of Hearts";
   trumpHeart[10] = "6 of Hearts";
   trumpHeart[11] = "4 of Hearts";
   trumpHeart[12] = "3 of Hearts";
   trumpHeart[13] = "2 of Hearts";

   const char *trumpDiamonds[53];
   trumpDiamonds[1] = "5 of Diamonds";
   trumpDiamonds[2] = "Jack of Diamonds";
   trumpDiamonds[3] = "Ace of Hearts";
   trumpDiamonds[4] = "King of Hearts";
   trumpDiamonds[5] = "Queen of Hearts";
   trumpDiamonds[6] = "10 of Hearts";
   trumpDiamonds[7] = "9 of Hearts";
   trumpDiamonds[8] = "8 of Hearts";
   trumpDiamonds[9] = "7 of Hearts";
   trumpDiamonds[10] = "6 of Hearts";
   trumpDiamonds[11] = "4 of Hearts";
   trumpDiamonds[12] = "3 of Hearts";
   trumpDiamonds[13] = "2 of Hearts";


   int i;
   //int rank[52];
   int player1Score;
   int player2Score;
   int player1Card;
   int player2Card;
   char *trumpCard = cardNames[12];
   char *player1PlayedCard;
   char *player2PlayedCard;


   char *player1Deck[6];
   player1Deck[1] = cardNames[1];
   player1Deck[2] = cardNames[2];
   player1Deck[3] = cardNames[3];
   player1Deck[4] = cardNames[4];
   player1Deck[5] = cardNames[5];


   char *player2Deck[6];
   player2Deck[1] = cardNames[14];
   player2Deck[2] = cardNames[15];
   player2Deck[3] = cardNames[16];
   player2Deck[4] = cardNames[17];
   player2Deck[5] = cardNames[18];

   /*char *player3Deck[6];
   player3Deck[1] = cardNames[27];
   player3Deck[2] = cardNames[28];
   player3Deck[3] = cardNames[29];
   player3Deck[4] = cardNames[30];
   player3Deck[5] = cardNames[31];

   char *player4Deck[6];
   player4Deck[1] = cardNames[40];
   player4Deck[2] = cardNames[41];
   player4Deck[3] = cardNames[42];
   player4Deck[4] = cardNames[43];
   player4Deck[5] = cardNames[44]; */

   for (i = 1; i < 53; i++)
   {
       printf("Card no.%d: %s\n",i, cardNames[i]);
       printf("\n");
   }  

   for (i = 1; i < 6; i++)
   {
       printf("Player 1 Deck: Card no.%d:\t%s\n", i, player1Deck[i]);

   }

   printf("\n");


   for (i = 1; i < 6; i++)
   {
       printf("Player 2 Deck: Card no.%d:\t%s\n", i, player2Deck[i]);

   }
  
   printf("\n");


   /*for (i = 1; i < 6; i++)
   {
       printf("Player 3 Deck: Card no.%d\t%s\n", i, player3Deck[i]);

   }

   printf("\n");


   for (i = 1; i < 6; i++)
   {
       printf("Player 4 Deck: Card no.%d\t%s\n", i, player4Deck[i]);

   } */


  

   do
   {
       printf("The trump card is the %s \n", trumpCard);

       printf("Player 1 please select the card number you wish to play \n");
       scanf("%d", &player1Card);

       printf("Player 2 please select the card number you wish to play \n");
       scanf("%d", &player2Card);


       player1PlayedCard = player1Deck[player1Card];

       player2PlayedCard = player2Deck[player2Card];

       printf("Player 1 played %s \n", player1PlayedCard);
       printf("Player 2 played %s \n", player2PlayedCard);

   } while (player1Score < 25 || player2Score < 25);

}

Answer
Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.

Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.