<mosaic.cnfolio.com>
PROGRAM
  1. /*START
  2.      two players obtain two to ten cards
  3.      calculate number of cards in players hands
  4.      THEN
  5.         rearrange cards so their hand starts with the highest
  6.         THEN
  7.             both players draw first card
  8.             IF
  9.              one player has a higher card
  10.              THEN
  11.                 display the winner message to player with higher card
  12.              ELSE
  13.                 both players draw another card
  14.                 IF
  15.                  one player has a higher card
  16.                  THEN
  17.                     display the winner message to player with higher card
  18.                  ELSE
  19.                     IF
  20.                      one player runs out of cards
  21.                      THEN
  22.                         show the winner message to player with cards left
  23.                      ELSE     
  24.                         IF
  25.                          both players run out of cards
  26.                          THEN
  27.                             diplay the draw message
  28.                       END IF
  29.                 END IF
  30.           END IF
  31.     END IF
  32. END*/
  33.  
  34.  
  35.  
  36.  
  37. #include <stdio.h>
  38. #include <stdlib.h>
  39.  
  40. int main( void )
  41. {
  42. //Player 1 error messages
  43.   int player_1_hand;
  44.   int player_2_hand;
  45.   scanf("%d",&player_1_hand);
  46.   if(player_1_hand <2 || player_1_hand >10)
  47.   {
  48.   printf("Error, Player 1 handsize not in the correct range, enter a number between 2 and 10");
  49.   return (0);
  50.   }
  51.   int player_1_card[10] = {0};
  52.   int player_2_card[10] = {0};
  53.   for (int i = 0; i < player_1_hand; ++i){
  54.   scanf("%d" ,&player_1_card[i]);}
  55.   for (int i = 0; i < player_1_hand; ++i)
  56.   for (int i = 0; i < player_1_hand; ++i)
  57.  {
  58.   if(player_1_card[i] < 1)
  59.   {
  60.   printf("Error,  Player 1 has inputed a number that is too small. Enter numbers bigger than 0");
  61.   return (0);
  62.   }
  63.   else if(player_1_card[i]>10)
  64.   {
  65.   printf("Error, Player 1 has inputed a number that is too big. Enter numbers smaller than 11");
  66.   return(0);
  67.   } 
  68.   }
  69.   //Player 1 bubble sort
  70.   int temp;
  71.   int j;
  72.   for (int j = 0 ; j < player_1_hand - 1; j++){
  73.   for (int i = 0; i < player_1_hand -1; i++){
  74.   if (player_1_card[i] < player_1_card[i+1]){
  75.   temp = player_1_card[i];
  76.   player_1_card[i] = player_1_card[i+1];
  77.   player_1_card[i+1] = temp;
  78.   }
  79.   }
  80.   }
  81.   printf("\nplayer 1 cards: ");
  82.   for (int i = 0; i < player_1_hand; i++){
  83.   printf("%d " , player_1_card[i]);
  84.   }
  85.   //Player two's error messages
  86.   scanf("%d",&player_2_hand);
  87.   if(player_2_hand <2 || player_2_hand >10)
  88.   {
  89.   printf("Error, Player 2 handsize not in the correct range, enter a number between 2 and 10");
  90.   return (0);
  91.   }
  92.   for (int i = 0; i < player_2_hand; ++i){
  93.   scanf("%d" ,&player_2_card[i]);}
  94.   for (int i = 0; i < player_2_hand; ++i)
  95.   for (int i = 0; i < player_2_hand; ++i)
  96.  {
  97.   if(player_2_card[i] < 1)
  98.   {
  99.   printf("Error, Player 2 has inputed a number that is too small. Enter numbers bigger than 0");
  100.   return (0);
  101.   }
  102.   else if(player_2_card[i]>10)
  103.   {
  104.   printf("Error, Player 2 has inputed a number that is too big. Enter numbers smaller than 11");
  105.   return(0);
  106.   } 
  107.   }
  108.  //Player 2 bubble sort
  109.  
  110.   for (int j = 0 ; j < player_2_hand - 1; j++)
  111.   {
  112.   for (int i = 0; i < player_2_hand -1; i++)
  113.   {
  114.   if (player_2_card[i] < player_2_card[i+1])
  115.   {
  116.   temp = player_2_card[i];
  117.   player_2_card[i] = player_2_card[i+1];
  118.   player_2_card[i+1] = temp;
  119.   }
  120.   }
  121.   }
  122.   printf("\nplayer 2 cards: ");
  123.   for (int i = 0; i < player_2_hand; i++){
  124.   printf("%d " , player_2_card[i]);
  125.   }
  126.   //Winner declarations
  127.   printf("\n");
  128.   {for (int i=0; i<player_1_card; ++i){
  129.   if(player_1_card[i] < player_2_card[i])
  130.   {
  131.   printf("player 2 wins \n");
  132.   return 0;
  133.   }else if (player_1_card[i] > player_2_card[i]){
  134.   printf("player 1 wins \n");
  135.   return 0;
  136.   }else if (player_1_card[i] == player_2_card[i]) {
  137.   printf("Draw\n");
  138.  
  139.   }
  140.   }
  141.   }
  142.   }