daily pastebin goal
46%
SHARE
TWEET

Untitled

a guest Jun 14th, 2018 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Card dealing program */
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <time.h>
  6.  
  7. void shuffle(int [][13]);
  8. void deal(int [][13], char *[], char *[], int[], int[]);
  9. void pair(int [], int []);
  10.  
  11. void main()
  12. {
  13.     char *suit[4]={"Hearts", "Diamonds", "Clubs", "Spades"};
  14.     char *face[13]={"Ace", "Deuce", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"};
  15.  
  16.     int myFace[5];
  17.     int mySuit[5];
  18.  
  19.     int deck[4][13] = {0};
  20.  
  21.     srand(time(0));
  22.     shuffle(deck);
  23.     deal(deck, face, suit, myFace, mySuit);
  24.  
  25.     pair(myFace, mySuit);
  26.  
  27.  
  28. }
  29. void shuffle(int workdeck[][13])
  30. {
  31.     int card, row, column;
  32.  
  33.     for(card = 1; card <= 52; card++)
  34.     {
  35.         row = rand() % 4;
  36.         column = rand() % 13;
  37.  
  38.         while(workdeck[row][column] != 0)
  39.         {
  40.             row = rand() % 4;
  41.             column = rand() % 13;
  42.         }
  43.  
  44.         workdeck[row][column] = card;
  45.     }
  46. }
  47.  
  48. void deal(int workdeck2[][13], char *workface[], char *worksuit[], int myFace[], int mySuit[])
  49. {
  50.     int card, row, column, i;
  51.  
  52.     for (card = 1; card <= 5; card++)
  53.         for (row = 0; row <= 3; row++)
  54.             for (column = 0; column <= 12; column++)
  55.                 if (workdeck2[row][column] == card)
  56.                 {
  57.                     printf("%5s of %-8s",
  58.                     workface[column], worksuit[row]);
  59.  
  60.                     if (card % 2 == 0)
  61.                         puts("");
  62.                     else
  63.                         printf("\t");
  64.  
  65.  
  66.                     myFace[card - 1] = row;
  67.                     mySuit[card - 1] = column;
  68.                     break;
  69.                 }
  70.  
  71.  
  72. }
  73.  
  74. void pair(int myFace[], int mySuit[])
  75. {
  76.     int i, j, pairQ;
  77.  
  78.     for(i = 0; i < 5; i++){
  79.  
  80.         for(j = i + 1; j < 4; j++){
  81.  
  82.             if(myFace[i] == myFace[j]){
  83.                 pairQ++;
  84.             }
  85.  
  86.         }
  87.  
  88.     }
  89.  
  90.  
  91.    switch(pairQ){
  92.  
  93.         case 0:
  94.             printf("Nothing.");
  95.         break;
  96.         case 2:
  97.             printf("Pair.");
  98.         break;
  99.  
  100.         case 4:
  101.             printf("2 Pair");
  102.         break;
  103.         case 6:
  104.             printf("3 of a kind");
  105.         break;
  106.         case 7:
  107.             printf("4 of a kind.");
  108.         break;
  109.    }
  110.  
  111. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top