<mosaic.cnfolio.com>
PROGRAM
  1. /*
  2. START
  3.    DISPLAY Hi! welcome to the game of cards
  4.  
  5.  
  6.       DISPLAY message GAME!
  7.      P1 starts with cards handsize
  8.      P2 starts with cards  handsize
  9. IF
  10.        DISPLAY message P1 turn
  11. THEN
  12.        DISPLAY message P1 enter a number between 2 to 10
  13. ELSE IF
  14.         P1 input number lower than 2 or higher than 10
  15. THEN
  16.        DISPLAY message Error enter a number between 2 to 10
  17. END IF
  18.  
  19. DO WHILE
  20.         Sort P1 cards from highest to lowest
  21.         Sort P2 cards from highest to lowest
  22. IF
  23.         P1 enters a number a higher than P2
  24. THEN
  25.           DISPLAY message P1 WINS!
  26. ELSE IF
  27.           P2 enters a number higher than P1
  28. THEN
  29.           DISPLAY message P2 WINS!
  30. ELSE IF
  31.           P1 and P2 run out of cards
  32. THEN
  33.          DISPLAY message IT'S A DRAW!
  34.    
  35.          END IF
  36.      END IF
  37.    END IF
  38.      
  39. */
  40.  
  41. #include <stdio.h>
  42.  
  43.  int main( void )
  44.  {
  45. int P1_input;
  46. int P2_input;
  47. int P1_handsize = 0;
  48. int P2_handsize = 0;
  49. int P1_numberofcards [10]={0};
  50. int P2_numberofcards [10]={0};
  51. int game_number=1;
  52.  
  53. //player one's turn//
  54. printf("GAME %d\n", game_number);
  55.  
  56. (P1_handsize<2||P1_handsize >10);{
  57. scanf("%d", &P1_handsize);
  58. printf("%d\n", P1_handsize);}
  59.  
  60. if(P1_handsize < 2){
  61. printf("P1 ENTER A NUMBER BETWEEN 2 to 10\n");
  62. return 0;
  63. } else if (P1_handsize > 10){
  64.  printf("P1 ENTER A NUMBER BETWEEN 2 to 10\n");
  65.  return 0;
  66. }
  67.  
  68.  
  69.  
  70. scanf("%d",&P1_input);
  71. if(P1_input<1||P1_input >10){
  72. printf("Error please enter a number between 2 to 10\n");
  73. exit(0);
  74. }
  75.            
  76.            int i; {     
  77. for (i =0;i<P1_input;i++)
  78. {
  79. scanf("%d",&P1_numberofcards[i]);
  80.  
  81. }
  82. // Player two's turn
  83.  
  84. (P2_handsize<2||P2_handsize >10);{
  85. scanf("%d", &P2_handsize);
  86. printf("%d\n", P2_handsize);}
  87.  
  88. if(P2_handsize < 2){
  89. printf("P2 ENTER A NUMBER BETWEEN 2 to 10\n");
  90. return 0;
  91. } else if (P2_handsize > 10){
  92.  printf("P2 ENTER A NUMBER BETWEEN 2 to 10\n");
  93.  return 0;
  94. }
  95.  
  96.  
  97. scanf("%d",&P2_input);
  98. if(P2_input<1||P2_input >10){
  99. printf("Error please enter a number between 2 to 10\n");
  100. exit(0);
  101. }
  102.            
  103.            int i; {     
  104. for (i =0;i<P2_input;i++)
  105. {
  106. scanf("%d",&P2_numberofcards[i]);
  107. }
  108. }
  109. // bubble sort
  110.  
  111. int temp;
  112.            
  113. for (int j =0;j<P1_input-1;j++)
  114. {         
  115. for (int i =0;i<P1_input-1;i++)
  116.  
  117. if (P1_numberofcards[i] < P1_numberofcards[i+1])
  118. {
  119. temp = P1_numberofcards[i];
  120.  P1_numberofcards[i]= P1_numberofcards[i+1];
  121. P1_numberofcards[i+1] = temp;
  122. }
  123. }
  124. for (int i =0; i < P1_input; i++)
  125. { 
  126. printf("%d", P1_numberofcards[i]);
  127. }
  128. // bubblesort for P2
  129.  
  130. for (int j =0;j>P2_input-1;j++)
  131. {
  132. for (int i =0;i>P2_input-1;i++)
  133. {
  134. if (P2_numberofcards[i]> P2_numberofcards[i+1])
  135. {
  136. temp = P2_numberofcards[i];
  137. P2_numberofcards[i]=P2_numberofcards[i+1];
  138. P2_numberofcards[i+1]= temp;
  139. }
  140. }
  141. }
  142. for (int i =0;i<P2_input;i++)
  143. {
  144. printf("%d", P2_numberofcards[i]);
  145. }
  146.  
  147. if (P1_numberofcards [0] > P2_numberofcards [0])
  148. {
  149. printf("P1 WINS!");
  150. }
  151.  
  152. else if (P1_numberofcards [0] < P2_numberofcards [0])
  153. {
  154. printf("P2 WINS!");
  155. }
  156. else if (P1_numberofcards [0] == P2_numberofcards [0])
  157. {
  158. printf("IT'S A DRAW!");
  159. }
  160. }
  161. }