<mosaic.cnfolio.com>
PROGRAM
  1. /*The previous saved file was done before pseudo code was refined and so
  2. I needed to start at the beginning*/
  3.  
  4. /*START
  5. player 1's cards are chosen for them
  6.  
  7. IF player 1's number of cards is less than 2
  8.    Display "Error: The total inputted must be greater than 1"
  9.    END PROGRAMME
  10. END IF
  11.  
  12. IF player 1's number of cards is greater than 10
  13.    Display "Error The total inputted must be less than 11"
  14.    END PROGRAMME
  15. END IF
  16.  
  17. WHILE number of cards inputted is less than the total of cards chosen
  18. for player 1
  19.    input another card value
  20.    check to see if number of cards inputted is equal to chosen for player 1
  21. END While
  22.  
  23. player 2's cards are chosen for them
  24.  
  25. IF player s's number of cards is less than 2
  26.    Display "Error: The total inputted must be greater than 1"
  27. END IF
  28.  
  29. IF player 2's number of cards is greater than 10
  30.    Display "Error The total inputted must be less than 11"
  31. END IF
  32.  
  33. WHILE number of cards inputted is less than the total of cards chosen
  34. for player 2
  35.    input another card value
  36.    check to see if number of cards inputted is equal to chosen for player 2
  37. END While
  38.  
  39. SORT player 1's cards into decending order
  40.  
  41. SORT player 2's cards into decending order
  42.  
  43. find sum of total of first card from both player 1 minus player 2
  44.  
  45. IF sum of cards is positive
  46.    Display "player 1 wins"
  47. END IF
  48.  
  49. IF sum of cards is negative
  50.    Display "player 2 wins"
  51. END IF
  52.  
  53. WHILE sum of cards is equal to 0
  54.    find sum of next set of cards
  55.    check the total to make sure it isnt 0
  56. END WHILE
  57.  
  58. IF last total of cards is equal to 0
  59.    Display "Draw"
  60. END IF*/
  61.    
  62. #include <stdio.h>
  63.  
  64. int main(void)             /*the main function allows code to be used
  65.                              inside the program*/
  66. {
  67.    
  68. int a[10], i=0, j=0, n, t; /*these are the variables used in the loop to
  69.                              input player 1's hand and are classified as
  70.                              integers meaning that they are only limited to
  71.                              whole numbers*/
  72.    
  73.    
  74.    scanf("%d", &n);    /*this allows the user to input the number of
  75.                              cards in player 1's hand*/
  76.    
  77.    if(n<2)           
  78.       {printf("Error: Player 1's hand must be greater than 1 cards");
  79.       exit(1);}            /*this if function displays the following error
  80.                              message if the number of cards in player 1's
  81.                              hand is less than 2*/
  82.    if(n>10)
  83.       {printf("Error: player 1's hand must be less than 10 cards");
  84.       exit(1);}            /*this if function displays the following error
  85.                              message if the number of cards in player 1's
  86.                              hand is greater than 10*/
  87.    
  88.    for (i = 0; i <n; i++)
  89.    {
  90.     scanf("%d", &a[i]);
  91.    }
  92.    for (j=0 ; j<(n-1) ; j++)
  93.    { 
  94.       for(i=0 ; i<(n-1) ; i++)
  95.       {
  96.          if(a[i+1] < a[i])
  97.          {
  98.             t = a[i];
  99.             a[i] = a[i+1];
  100.             a[i + 1] = t;
  101.          }
  102.       }
  103.     }        /*the series of loops above allows input
  104.                       of the cards that have been assigned to
  105.                              player 1 and then orders it into decending
  106.                              order*/
  107.                        
  108.   
  109.    int a2[10], i2=0, j2=0, n2, t2;
  110.                            /*similarly to player 1 the above are the
  111.                              variables used in the loop to input player 2's
  112.                              hand and are classified as integers meaning
  113.                              that they are only limited to whole numbers*/
  114.    
  115.    
  116.    scanf("%d", &n2);   /*this allows the user to input the number of
  117.                              cards in player 2's hand*/
  118.    
  119.    if(n2<2)
  120.       {printf("Error: Player 2's hand must be greater than 1 cards");
  121.       exit(1);}
  122.                            /*this if function displays the following error
  123.                              message if the number of cards in player 2's
  124.                              hand is less than 2*/
  125.    if(n2>11)
  126.       {printf("Error: player 2's hand must be less than 10 cards");
  127.       exit(1);}
  128.                            /*this if function displays the following error
  129.                              message if the number of cards in player 2's
  130.                              hand is greater than 10*/
  131.    
  132.    for (i2 = 0; i2 <n2; i2++)
  133.    {
  134.     scanf("%d", &a2[i2]);
  135.    }
  136.    for (j2=0 ; j2<(n2-1) ; j2++)
  137.    { 
  138.       for(i2=0 ; i2<(n2-1) ; i2++)
  139.       {
  140.          if(a2[i2+1] < a2[i2])
  141.          {
  142.             t2 = a2[i2];
  143.             a2[i2] = a2[i2+1];
  144.             a2[i2 + 1] = t2;
  145.          }
  146.       }
  147.     }
  148.                     /*the series of loops above allows input
  149.                       of the cards that have been assigned to
  150.                              player 2 and then orders it into decending
  151.                              order*/
  152.  
  153.    int total, total2, total3, total4, total5, total6;
  154.    int total7, total8, total9; /*these are variables being used in the
  155.                                  if functions below and again are
  156.                                  characterised as integes*/
  157.    
  158.    total=a[n-1]-a2[n2-1];
  159.    
  160.    total2=a[n-2]-a2[n2-2];
  161.    
  162.    total3=a[n-3]-a2[n2-3];
  163.    
  164.    total4=a[n-4]-a2[n2-4];
  165.    
  166.    total5=a[n-5]-a2[n2-5];
  167.    
  168.    total6=a[n-6]-a2[n2-6];
  169.    
  170.    total7=a[n-7]-a2[n2-7];
  171.    
  172.    total8=a[n-8]-a2[n2-8];
  173.    
  174.    total9=a[n-9]-a2[n2-9];
  175.                               /*above are the variables being assigned
  176.                                 to equations that minus the number in a
  177.                                 specific poisition in player 2's decending
  178.                                 hand of cards from the number in player 1's
  179.                                 decending hand of cards. So "total" is
  180.                                 player 1's 1st card minus player 2's 1st
  181.                                 card andf so on*/
  182.    
  183.                               /*Below are a series of if function used in
  184.                                 order to determine who has won the game.
  185.                                 It first subtracts the value of player 2's
  186.                                 first card with player 1's first card.
  187.                                 if it is 0 it moves onto their second.
  188.                                 if it is another 0 it moves onto the
  189.                                 third and so on until the tenth card.
  190.                                 if the sum of the tenth card is still zero
  191.                                 the game is classed as a draw*/
  192.    if(total>0)
  193.       {printf("\n player 1 wins");}
  194.      
  195.    if(total<0)
  196.       {printf("\n player 2 wins");}
  197.      
  198.    if(total==0 && n==2 && n2==2)
  199.       {printf("draw");
  200.        exit(1);}
  201.      
  202.    if (total==0)
  203.       {if(total2>0 || n2<=2 && a2[n2-2]!=0)
  204.          {printf("\n player 1 wins");
  205.           exit(1);}
  206.                                  /*as the amount of values in the array is
  207.                                    determined by the amount of cards given
  208.                                    to either player 1 or 2. if I were to
  209.                                    exceed this it would give me random
  210.                                    numbers and so wouldn't show the correct
  211.                                    results. These limits in the if function
  212.                                    are to prevent my program from accessing
  213.                                    the erroneous values*/
  214.      
  215.       if(total2<0 || n<=2 && a[n-2]!=0)
  216.          {printf("\n player 2 wins");
  217.           exit(1);}
  218.          
  219.       if(total2==0 && n==3 && n2==3)
  220.       {printf("draw");       
  221.        exit(1);}
  222.        
  223.        if (total2==0)
  224.          {if(total3>0 || n2<=3 && a2[n2-3]!=0)
  225.             {printf("\n player 1 wins");
  226.              exit(1);}
  227.      
  228.          if(total3<0 || n<=3 && a[n-3]!=0)
  229.             {printf("\n player 2 wins");
  230.              exit(1);}
  231.          
  232.          if(total3==0 && n==4 && n2==4)
  233.            {printf("draw");
  234.            exit(1);}
  235.            
  236.          if (total3==0)
  237.             {if(total4>0 || n2<=4 && a2[n2-4]!=0)
  238.                {printf("\n player 1 wins");
  239.               exit(1);}
  240.      
  241.             if(total4<0 || n<=4 && a[n-4]!=0)
  242.                {printf("\n player 2 wins");
  243.                exit(1);}
  244.          
  245.             if(total4==0 && n==5 && n2==5)
  246.             {printf("draw");
  247.             exit(1);}
  248.              
  249.           if (total4==0)
  250.                {if(total5>0 || n2<=5 && a2[n2-5]!=0)
  251.                   {printf("\n player 1 wins");
  252.                  exit(1);}
  253.      
  254.                 if(total5<0 || n<=5 && a[n-5]!=0)
  255.                   {printf("\n player 2 wins");
  256.                  exit(1);}
  257.          
  258.                 if(total5==0 && n==6 && n2==6)
  259.                   {printf("draw");
  260.                 exit(1);}
  261.                    
  262.                 if (total5==0)
  263.                   {if(total6>0 || n2<=6 && a2[n2-6]!=0)
  264.                      {printf("\n player 1 wins");
  265.                    exit(1);}
  266.      
  267.                    if(total6<0 || n<=6 && a[n-6]!=0)
  268.                       {printf("\n player 2 wins");
  269.                     exit(1);}
  270.          
  271.                    if(total6==0 && n==7 && n2==7)
  272.                      {printf("draw");
  273.                   exit(1);}
  274.                    
  275.                    if (total6==0)
  276.                      {if(total7>0 || n2<=7 && a2[n2-7]!=0)
  277.                         {printf("\n player 1 wins");
  278.                      exit(1);}
  279.      
  280.                       if(total7<0 || n<=7 && a[n-7]!=0)
  281.                         {printf("\n player 2 wins");
  282.                      exit(1);}
  283.          
  284.                       if(total7==0 && n==8 && n2==8)
  285.                         {printf("draw");
  286.                     exit(1);}
  287.                          
  288.                       if (total7==0)
  289.                         {if(total8>0 || n2<=8 && a2[n2-8]!=0)
  290.                            {printf("\n player 1 wins");
  291.                        exit(1);}
  292.      
  293.                          if(total8<0 || n<=8 && a[n-8]!=0)
  294.                            {printf("\n player 2 wins");
  295.                        exit(1);}
  296.          
  297.                          if(total8==0 && n==9 && n2==9)
  298.                            {printf("draw");
  299.                       exit(1);}
  300.                          
  301.                          if (total8==0)
  302.                             {if(total9>0 || n2<=9 && a2[n2-9]!=0)
  303.                                {printf("\n player 1 wins");
  304.                           exit(1);}
  305.      
  306.                              if(total9<0 || n<=9 && a[n-9]!=0)
  307.                                {printf("\n player 2 wins");
  308.                           exit(1);}
  309.          
  310.                              if(total==0 && n==10 && n2==10)
  311.                                {printf("draw");
  312.                          exit(1);}}}}}}}}}}