<mosaic.cnfolio.com>
PROGRAM
  1. /* ----------------------------------------------------------------  PSEUDOCODE ------------------------------------------------------------------------
  2.  
  3.  
  4. START
  5.  
  6. VARIABLE I, J, K, L, HIGHEST
  7. VARIABLE Hand Quantity 1, Hand Quantity 2 = 0
  8. VARIABLE Hand Values 1[array], Hand Values 2[array]
  9.  
  10.  
  11. // INPUT SECTION
  12.  
  13. INPUT Hand Quantity 1
  14. END LOOP
  15.       INPUT Hand Value 1[array]
  16.    END LOOP
  17.  
  18. INPUT Hand Quantity 2
  19.    FOR LOOP
  20.       INPUT Hand Value 2[array]
  21.    END LOOP
  22.  
  23.  
  24. // ERROR DETECTION
  25.  
  26. IF Hand Quantity 1 > 1 OR <  10
  27.    OUTPUT Rejection Message
  28.  
  29. IF Hand Quantity 2 > 1 OR < 10
  30.    OUTPUT Rejection Message
  31.  
  32. FOR LOOP
  33.    IF Hand Values 1[array] > 1 OR < 10
  34.       OUTPUT Rejection Message
  35. END LOOP 
  36.    
  37. FOR LOOP
  38.    IF Hand Values 2[array] > 1 OR < 10
  39.       OUTPUT Rejection Message
  40. END LOOP
  41.  
  42. FOR LOOP
  43.    IF Hand Values 1[array] DOESN’T EQUAL Hand Quantity 1
  44.       OUTPUT Rejection Message
  45. END LOOP
  46.  
  47. FOR LOOP
  48.    IF Hand Values 2[array] DOESN’T EQUAL Hand Quantity 2
  49.       OUTPUT Rejection Message
  50. END LOOP
  51.  
  52.  
  53. // SORT ARRAY
  54.  
  55. FOR LOOP
  56. Sort Array Highest to Lowest
  57. END
  58.  
  59.  
  60. // SET HIGHEST HAND
  61.  
  62. IF Hand Quantity 1 > Hand Quantity 2
  63.    SET high to Hand Quantity 1
  64. ELSE
  65.    SET high to Hand Quantity 2
  66. END
  67.  
  68.  
  69. // COMPARING HANDS
  70.  
  71. FOR LOOP
  72.    IF Hand Value 1[array] > Hand Value 2[array]
  73.    OUTPUT Player 1 Wins!
  74.    END
  75.    
  76.    IF Hand Value 1[array] < Hand Value 2[array]
  77.    OUTPUT Player 2 Wins!
  78.    END
  79.  
  80. END LOOP
  81.    
  82.    IF Hand Value 1[array] = Hand Value 2[array]
  83.    OUTPUT It’s a Draw!
  84.  
  85. END
  86.  
  87. /* -------------------------------------------------------------- START OF THE MAIN PROGRAM ----------------------------------------------------------------  */
  88. #include <stdio.h>
  89.      int main (){
  90.  
  91. /* ---------------------------------------------------------------- VARIABLES FOR INPUTS ----------------------------------------------------------------  */
  92.  
  93.   int i, j, k, l, high;  /* Pointers for various loops, high is used to store the data on the highest hand out of both players */
  94.   int Player1Quantity, Player2Quantity = 0/* Variables to store the data on the amount of cards the players have */
  95.   int Player1Hand[10], Player2Hand[10] = {0};   /* The array tables for storing data on the players hand */
  96.  
  97.  
  98. /* ----------------------------------------------------------------   INPUTS FOR PLAYERS   ----------------------------------------------------------------  */
  99.  
  100.   scanf ("%d", &Player1Quantity);   /* Takes the amount of cards player 1 has in their hand */
  101.   for (i = 0; i < Player1Quantity; i++)
  102.     {
  103.       scanf ("%d", &Player1Hand[i]);   /* For loop scans the second line the specified amount of times, if they enter 2 as their quantity it will scan the second line twice */
  104.  
  105.     }
  106.  
  107.  
  108.  
  109.   scanf ("%d", &Player2Quantity);   /* Takes the amount of cards player 2 has in their hand */
  110.   for (i = 0; i < Player2Quantity; i++)
  111.     {
  112.       scanf ("%d", &Player2Hand[i]);   /* For loop scans the second line the specified amount of times */
  113.  
  114.     }
  115.  
  116.  
  117.  
  118. /* ----------------------------------------------------------------  ERROR CHECKING   ---------------------------------------------------------------- */
  119.  
  120.  
  121.   /* Only accepts cards between 2 and 10 for the Player#Quantity Field */
  122.  
  123.   if (Player1Quantity <= 1 || Player1Quantity > 11)
  124.     {
  125.       printf
  126.    ("Player 1 has entered an illegal amount of cards, you are allowed between 2 and 10 cards \n");
  127.  
  128.       return 0;
  129.  
  130.     }
  131.   else if (Player2Quantity <= 1 || Player2Quantity > 11)
  132.     {
  133.       printf
  134.    ("Player 2 has entered an illegal amount of cards, you are allowed between 2 and 10 cards  \n");
  135.  
  136.       return 0;
  137.  
  138.     }
  139.  
  140.  
  141.  
  142.  
  143.   /* Only accepts values between 1 and 10 for the Player1Hand Field */
  144.  
  145.   for (i = 0; i < Player1Quantity; i++)
  146.     {
  147.       if (Player1Hand[i] < 1 || Player1Hand[i] > 10)
  148.    {
  149.      printf ("Player 1 has invalid values in their hand.");
  150.  
  151.      return 0;
  152.  
  153.    }
  154.     }
  155.  
  156.  
  157.    /* Only accepts values between 1 and 10 for the Player2Hand Field */
  158.  
  159.    for (i = 0; i < Player2Quantity; i++)
  160.     {
  161.       if (Player2Hand[i] < 1 || Player2Hand[i] > 10)
  162.    {
  163.      printf ("Player 2 has invalid values in their hand.");
  164.  
  165.      return 0;
  166.  
  167.    }
  168.  
  169.     }
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178. /* ---------------------------------------------------------------   SORTING ARRAY  ------------------------------------------------------------------ */
  179.  
  180.  
  181.  
  182.   for (i = 0; (i <= Player1Quantity); i++)
  183.     {
  184.       for (j = 0; j < (Player1Quantity - 1); j++)
  185.    {
  186.      if (Player1Hand[j + 1] > Player1Hand[j])   /* Changing the < and > will change the order of the array */
  187.        {
  188.          k = Player1Hand[j];
  189.          Player1Hand[j] = Player1Hand[j + 1];
  190.          Player1Hand[j + 1] = k;
  191.  
  192.        }
  193.    }
  194.     }
  195.  
  196.  
  197.  
  198.   for (i = 0; (i <= Player2Quantity); i++)
  199.     {
  200.       for (j = 0; j < (Player2Quantity - 1); j++)
  201.    {
  202.      if (Player2Hand[j + 1] > Player2Hand[j])   /* Changing the < and > will change the order of the array */
  203.        {
  204.          l = Player2Hand[j];
  205.          Player2Hand[j] = Player2Hand[j + 1];
  206.          Player2Hand[j + 1] = l;
  207.  
  208.        }
  209.    }
  210.     }
  211.  
  212.  
  213.  
  214.  
  215.  
  216. /* ----------------------------------------------------------------  DETERMINE HIGHEST HAND  ----------------------------------------------------------------  */
  217.  
  218.  
  219.   /* This is used to determine who has the highest hand, and is used as the target for my comparing hands sequence which comes up next */
  220.  
  221.   if (Player1Quantity > Player2Quantity)
  222.     {
  223.       high = Player1Quantity;
  224.     }
  225.  
  226.   else
  227.     {
  228.       high = Player2Quantity;
  229.     }
  230.  
  231.  
  232.  
  233.  
  234. /* ----------------------------------------------------------------  COMPARING HANDS  ----------------------------------------------------------------  */
  235.  
  236.  
  237.  
  238.   for (i = 0; i < high; i++)
  239.     {
  240.  
  241.  
  242.       if (Player1Hand[i] > Player2Hand[i])
  243.    {
  244.      printf ("Player 1 wins with the card %d!\n", Player1Hand[i]);
  245.      return 0;
  246.    }
  247.    
  248.  
  249.  
  250.  
  251.       if (Player1Hand[i] < Player2Hand[i])
  252.    {
  253.      printf ("Player 2 wins with the card %d!\n", Player2Hand[i]);
  254.  
  255.      return 0;
  256.      
  257.    }
  258.  
  259.     }
  260.  
  261. /* Player1Hand[i] == Player2Hand[i];*/
  262.   if (i == high)
  263.   {
  264.     printf ("\nIt's a Draw!");
  265.  
  266.  
  267.     return;
  268.   }
  269.  
  270.      }