<mosaic.cnfolio.com>
PROGRAM
  1. /*START
  2. WHILE both player’s hand sizes are not over or equal to 2 and under or equal to 10
  3.    Obtain hand size for player 1 and player 2
  4.    IF the hand sizes are not between 2 and 10
  5.       Display which player’s hand size is under 2 or over 10
  6.    END IF
  7.    IF the inputs aren't an integer between 2 and 10
  8.       display enter an integer value between 2 and 10
  9.    END IF
  10. END WHILE
  11. WHILE Cards in both players’ hands are over and equal to 1 and under or equal to 10
  12.    Obtain cards equal to hand size for player 1 and player 2
  13.    IF the card obtained in any instance is not between 1 and 10
  14.       Display which player’s card is under 1 or over 10
  15.    END IF
  16.    IF the inputs aren't an integer value between 1 and 10
  17.       display enter an integer value between 1 and 10
  18.    END IF
  19. END WHILE
  20. WHILE both players hands aren’t sorted
  21. Sort a player’s hand in ascending order
  22. Swap player being checked
  23. END WHILE
  24. WHILE one of these conditions is not met
  25.    Go to the next card in both players’ hands
  26.    IF player 1’s card is bigger than player 2’s
  27.       Display Player 1 wins
  28.    END IF
  29.    IF player 2’s card is bigger than player 1’s
  30.       Display Player 2 wins
  31.    END IF
  32.    IF there are 0 cards in both players’ hands
  33.       Display The game ends in a draw
  34.    END IF
  35.    IF there are 0 cards in player 1’s hand
  36.       Display Player 2 wins
  37.    END IF
  38.    IF there are 0 cards in player 2’s hand
  39.       Display Player 1 wins
  40.    END IF
  41. END WHILE
  42. END*/
  43.  
  44. #include <stdio.h>
  45. #include <stdlib.h>
  46. #include <math.h>
  47. int main()
  48. {
  49.    double temp=0;
  50.    double handsizep1=0;
  51.    double handsizep2=0;
  52.    double playeronehand[10];
  53.    double playertwohand[10];
  54.    int j=0; /*Used as a counter with a short input*/
  55.    int i=0; /*Used as a counter that doesn't take too long to type out*/
  56.    /*Player one obtaining cards and hand size*/
  57.    while(handsizep1>10 || handsizep1<2)
  58.    {
  59.       scanf("%f", &handsizep1);
  60.       handsizep1=ceil(handsizep1); /*Used to change floats into integers so that such inputs could be used*/
  61.       if(handsizep1>10)
  62.       {
  63.          printf("player 1 hand size is above the limit");
  64.       }
  65.       else if(handsizep1<2)
  66.       {
  67.          printf("player 1 hand size is below the limit or player 1 has entered an ascii character");
  68.       }
  69.    }
  70.    for(i=0;i < handsizep1; i++)
  71.    {
  72.      scanf(" %f", &playeronehand[i]);
  73.      playeronehand[i]=ceil(playeronehand[i]); /*Used to round float values up*/
  74.       if(playeronehand[i]>10)
  75.       {
  76.          printf("player 1 hand size is above the limit");
  77.          i--;
  78.       }
  79.       else if(playeronehand[i]<1)
  80.       {
  81.          printf("player 1 hand size is below the limit or player has entered an ascii character");
  82.          i--;
  83.       }     
  84.    }
  85.    /*Player two inputs*/
  86.    while(handsizep2>10 || handsizep2 <2)
  87.    {
  88.       scanf("%f", &handsizep2);
  89.       handsizep2=ceil(handsizep2); /*Used to round float values up*/
  90.       if(handsizep2>10)
  91.       {
  92.          printf("player 2's hand size is above the limit");
  93.       }
  94.       else if (handsizep2<2)
  95.       {
  96.          printf("player 2's hand size is under the limit or an ascii character has been entered");
  97.       }
  98.    }
  99.    for(i=0; i < handsizep2;i++)
  100.    {
  101.      scanf(" %f", &playertwohand[i]);
  102.      playertwohand[i]=ceil(playertwohand[i]); /*Used to round float values up*/
  103.      if(playertwohand[i]>10)
  104.       {
  105.          printf("player 2 hand size is above the limit");
  106.          i--;
  107.       }
  108.       else if(playertwohand[i]<1)
  109.       {
  110.          printf("player 2 hand size is below the limit or player has entered an ascii character");
  111.          i--;
  112.       }
  113.      
  114.    }
  115.    /*Sorting algorithms for both players*/
  116.    for(j=0; j<handsizep1-1; j++)
  117.    {
  118.      for(i=0; i<handsizep1-1;i++)
  119.       {
  120.         if(playeronehand[i]<playeronehand[i+1])
  121.          {
  122.             temp=playeronehand[i];
  123.             playeronehand[i]=playeronehand[i+1];
  124.             playeronehand[i+1]=temp;
  125.          }
  126.       }
  127.    }
  128.    
  129.    for(j=0; j<handsizep2-1; j++)
  130.    {
  131.      for(i=0; i<handsizep2-1; i++)
  132.       {
  133.         if(playertwohand[i]<playertwohand[i+1])
  134.          {
  135.            temp=playertwohand[i];
  136.             playertwohand[i]=playertwohand[i+1];
  137.             playertwohand[i+1]=temp;
  138.          }
  139.       }
  140.    }
  141.    /*Conditions to find the winner, in which if a condition has been obtained it exists the loop*/
  142.    for(i=0; i<10; i++)
  143.    {
  144.       handsizep1--;
  145.       handsizep2--;
  146.         if(playeronehand[i] > playertwohand[i])
  147.         {
  148.           printf("\nPlayer one wins!");
  149.           break;
  150.         }
  151.         else if(playeronehand[i] < playertwohand[i])
  152.         {
  153.           printf("\nPlayer two wins!");
  154.           break;
  155.         }           
  156.         if(handsizep1 == 0 && handsizep2 == 0)
  157.         {
  158.           printf("\nGame ends in a draw!");
  159.           break;
  160.         }
  161.         else if(handsizep1 ==0)
  162.         {
  163.           printf("\nPlayer two wins!");
  164.           break;
  165.         }
  166.         else if(handsizep2 ==0)
  167.         {
  168.           printf("\nPlayer one wins!");
  169.           break;
  170.         }
  171.    } 
  172.    return 0
  173. }