<mosaic.cnfolio.com>
PROGRAM
  1. /*
  2.    >>>> ---- ---- ---- ---- ---- ---- ---- ---- Pseudo Code ---- ---- ---- ---- ---- ---- ---- ---- <<<<
  3.    
  4.    START
  5.       
  6.       Get Player1's Hand
  7.       Get Player2's Hand
  8.      
  9.       Check Player1's Hand to ensure inputs are valid.
  10.       Check Player2's Hand to ensure inputs are valid.
  11.      
  12.       Sort Player1's Hand highest to lowest
  13.       Sort Player2's Hand highest to lowest
  14.      
  15.       WHILE Players have cards in their hand. Compare highest cards.
  16.      
  17.          IF Player1's highest card > Player2's highest card
  18.             Output PLAYER 1 WINS!
  19.          
  20.          ELSEIF Player2's highest card > Player1's highest card
  21.             Output PLAYER 2 Wins!
  22.          
  23.          ELSEIF
  24.             Player1's highest card = Player2's highest card AND Players Have more cards in hand.
  25.                Check next highest card in each hand.
  26.          
  27.          ELSEIF Player1's highest card = Player2's highest card AND No more cards in hand.
  28.             Output DRAW
  29.      
  30.       END WHILE
  31.      
  32.    END
  33.  
  34. */
  35.  
  36. /* >>>> ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- <<<< */
  37. /* >>>> ---- ---- ---- ---- ---- ---- ----     MAIN PROGRAM    ---- ---- ---- ---- ---- ---- ---- <<<< */
  38. /* >>>> ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- <<<< */
  39.  
  40.  
  41. #include <stdio.h>
  42.  
  43. int main() {
  44.  
  45. /* >>>> ---- ---- ---- ---- ---- ---- ---- ---- VARIABLES ---- ---- ---- ---- ---- ---- ---- ---- <<<< */
  46.  
  47.   int i = 0, j = 0, k = 0, l = 0, temp1 = 0, temp2 = 0/* Temporary variables used for loops and sorts. */
  48.   int Player1NoCards = 0, Player2NoCards = 0;            /* Variables to store the number of cards in the relevant players hand */
  49.   int Player1Cards[10] = {0}, Player2Cards[10] = {0};  /* Arrays to store the cards of each players hand */
  50.   int Highest;               /* What the highest number of cards are in one hand */
  51.  
  52.  
  53. /* >>>> ---- ---- ---- ---- ---- ---- ---- ----   INPUT   ---- ---- ---- ---- ---- ---- ---- ---- <<<<  */
  54.  
  55.   scanf ("%d", &Player1NoCards);    /* Gets the number of cards in Player 1's hand */
  56.   for (i = 0; i < Player1NoCards; i++) {
  57.     scanf ("%d", &Player1Cards[i]);      /* Stores values of each card in Player 1's hand in an array */
  58.   }
  59.  
  60.   scanf ("%d", &Player2NoCards);    /* Gets the number of cards in Player 2's hand */
  61.   for (i = 0; i < Player2NoCards; i++) {
  62.       scanf ("%d", &Player2Cards[i]);    /* Stores values of each card in Player 2's hand in an array */
  63.   }
  64.  
  65. /* >>>> ---- ---- ---- ---- ---- ---- ----   INPUT VALIDATION   ---- ---- ---- ---- ---- ---- ---- <<<<  */
  66.  
  67.   /* Only allowed 2 to 10 cards per hand */
  68.  
  69.   /* Player 1 Hand */
  70.    if (Player1NoCards < 2) {
  71.        printf("\nPlayer1 has too few cards in their hand. Must be 2 to 10 cards per hand.\n");
  72.        return 0;
  73.    } else if (Player1NoCards > 10) {
  74.        printf("\nPlayer1 has too many cards in their hand. Must be 2 to 10 cards per hand.\n");
  75.        return 0;
  76.    }
  77.  
  78.   /* Player 2 Hand */
  79.    if (Player2NoCards < 2) {
  80.       printf("\nPlayer2 has too few cards in their hand. Must be 2 to 10 cards per hand.\n");
  81.       return 0;
  82.    } else if (Player2NoCards > 10) {
  83.       printf("\nPlayer2 has too many cards in their hand. Must be 2 to 10 cards per hand.\n");
  84.       return 0;
  85.    }
  86.  
  87.   /* Only numbered cards 1 to 10 are allowed */
  88.  
  89.   /* Player 1 Hand */
  90.    for (i = 0; i < Player1NoCards; i++) {
  91.       if (Player1Cards[i] < 1 || Player1Cards[i] > 10) {
  92.          printf("\nPlayer 1 has invalid values in their hand. Values must be between 1 and 10.\n");
  93.          return 0;
  94.       }
  95.    }
  96.    
  97.   /* Player 2 Hand */
  98.    for (i = 0; i < Player2NoCards; i++) {
  99.       if (Player2Cards[i] < 1 || Player2Cards[i] > 10) {
  100.          printf("\nPlayer 2 has invalid values in their hand. Values must be between 1 and 10.\n");
  101.          return 0;
  102.       }
  103.    }
  104.  
  105.   /* Check all values entered are integers */
  106.  
  107.   /* Check number of values matches declared */
  108.  
  109. /* >>>> ---- ---- ---- ---- ---- ---- ---- ---- ARRAY SORT ---- ---- ---- ---- ---- ---- ---- ---- <<<<  */
  110.  
  111.   /* Player1Hand Sort */
  112.   for (i = 1; i <= Player1NoCards; i++) {
  113.     for (j = 0; j < (Player1NoCards - 1); j++) {
  114.        if (Player1Cards[j + 1] > Player1Cards[j]) {      /* Change < or > for ascending or descending */
  115.  
  116.          temp1 = Player1Cards[j];
  117.          Player1Cards[j] = Player1Cards[j + 1];
  118.          Player1Cards[j + 1] = temp1;
  119.  
  120.          }
  121.       }
  122.   }
  123.  
  124.   /* Player2Hand Sort */
  125.   for (k = 1; k <= Player2NoCards; k++) {
  126.       for (l = 0; l < (Player2NoCards - 1); l++) {
  127.        if (Player2Cards[l + 1] > Player2Cards[l]) {      /* Change < or > for ascending or descending */
  128.  
  129.          temp2 = Player2Cards[l];
  130.          Player2Cards[l] = Player2Cards[l + 1];
  131.          Player2Cards[l + 1] = temp2;
  132.  
  133.          }
  134.       }
  135.   }
  136.  
  137. /* >>>> ---- ---- ---- ---- ---- ---- ----  COMPARISON & OUTPUT  ---- ---- ---- ---- ---- ---- ---- <<<< */
  138.  
  139.   if (Player1NoCards > Player2NoCards) {        /* Used to find lowest number of cards. Then used as the maximum number of times to loop and check cards in arrays */
  140.       Highest = Player1NoCards;
  141.   } else {
  142.       Highest = Player2NoCards;
  143.   }
  144.  
  145.   for (i = 0; i < Highest; i++) {            /* Loops for the lowest number of cards times */
  146.       if (Player1Cards[i] > Player2Cards[i]) {
  147.        printf ("\nPlayer 1 WINS!\n");
  148.        return 0;
  149.       }
  150.       if (Player1Cards[i] < Player2Cards[i]) {
  151.        printf ("\nPlayer 2 WINS!\n");
  152.        return 0;
  153.       }
  154.   }
  155.  
  156.   printf ("\nIts a DRAW!\n");
  157.   return;
  158.  
  159. }