<mosaic.cnfolio.com>
PROGRAM
  1. /*
  2. Start
  3. Input the number of cards for player 1 between 2 to 10,
  4.  
  5. IF player 1 takes more than 10 or less than 2,
  6.  
  7. THEN display the error message
  8.  
  9. Restart the game
  10.  
  11. END IF
  12.  
  13. Input the value of each card for player 1,
  14.  
  15. IF the value is smaller than 1 or greater than 10,
  16.  
  17. THEN display error message.
  18.  
  19. Restart the game
  20.  
  21. END IF
  22.  
  23. Input the number of cards for player 2 in the range 2 to 10,
  24.  
  25. IF player 2 takes more than 10 or less than 2,
  26.  
  27. THEN display error message
  28.  
  29. REstart the game
  30.  
  31. END IF
  32.  
  33. Input the value of each card for player 2,
  34.  
  35. IF the value is smaller than 1 or greater than 10,
  36.  
  37. THEN display error message
  38.  
  39. REstart the game
  40.  
  41. END IF
  42. Display all input values for player 1,
  43.  
  44. Sort player 1 values of input from the biggest value to the smallest,
  45.  
  46. Display all input values for player 2,
  47.  
  48. Sort player 2 values of input from the biggest value to the smallest,
  49.  
  50. Compare the total amount of the values for each player,
  51.  
  52. IF player 1 value is greater than player 2 value,
  53.  
  54. THEN display winner message for player 1
  55.  
  56. REstart the game
  57.  
  58. END IF
  59.  
  60. IF player 2 value is greater than player 1 value, THEN DISPLAY WINEER MENSAGE FOR PLAYER 2
  61.  
  62. REstar the game
  63.  
  64. END IF
  65.  
  66. IF THE VALUES OF PLAYER 1 AND 2 ARE EGUAL,
  67.  
  68. THEN DISPLAY DRAW MENSAGE
  69.  
  70. Restart the game
  71. END IF
  72.  
  73. End
  74. */
  75.  
  76.  
  77.  
  78. #include <stdio.h>
  79.  
  80. int main()
  81. {
  82. int Player1sum, Player2sum;              // integer Variables
  83.  int P1[10],  P2[10];                  // integer Variables
  84.  int a,v,tempo,counter;                  // integer Variables
  85.  
  86.  scanf("%d",&Player1sum);
  87.  
  88.  if(Player1sum<2 || Player1sum>10){                   
  89.  printf("\n error, input numbers between 2 to 10, please try again" )//error message
  90.  
  91.  return;}
  92.  
  93. for (a= 0;a < Player1sum; a++){                                     //variable declared to 0
  94.  
  95. scanf("%d", &P1[a]);
  96. if(P1[a]<1 || P1[a]>10){
  97. printf("\n error only numbers 1 to 10, please try again");   //error message if player to play a value not allowed
  98. return;}
  99.  
  100. }
  101.  
  102.  
  103.  
  104. scanf("%d",&Player2sum);
  105.  
  106.  
  107.  
  108. if(Player2sum<2 || Player2sum>10){
  109.  
  110. printf("\n error, input numbers between 2 to 10, please try again" );   //error message
  111.  
  112. return;}
  113.  
  114.  
  115.  
  116. for (a= 0;a < Player2sum; a++){
  117.  
  118. scanf("%d", &P2[a]);
  119.  
  120.  
  121. if(P2[a]<1 || P2[a]>10){
  122. printf("\n error only numbers 1 to 10, please try again");   //error message if player to play a value not allowed
  123.  return;}
  124. }
  125.  
  126.  
  127. //sorting cards values in descending order (biggest to smallest) for player 1
  128. for(a=0; a<Player1sum; a++){
  129.        
  130.         for(v=a+1; v<Player1sum; v++){
  131.        
  132.          
  133.             if(P1[a] < P1[v]){
  134.            
  135.                 tempo     = P1[a];
  136.                 P1[a] = P1[v];
  137.                 P1[v] = tempo;}
  138.                 }
  139.                }
  140.              
  141.          for(a=0; a<Player1sum; a++)
  142. //sorting cards values in descending order (biggest to smallest) for player 2
  143. for(a=0; a<Player2sum; a++){
  144.        
  145.         for(v=a+1; v<Player2sum; v++){
  146.        
  147.          
  148.             if(P2[a] < P2[v]){
  149.            
  150.                 tempo     = P2[a];
  151.                 P2[a] = P2[v];
  152.                 P2[v] = tempo;}
  153.              }
  154.     }
  155.    
  156.     for(a=0; a<Player2sum; a++)
  157. //comparing both player and determine who is the winner of the game
  158. for(counter=0; counter<11; counter ++){
  159. if (P1[counter]>P2[counter]){
  160. printf("\nPlayer 1 it's the winner");
  161. return;
  162. }
  163. if (P2[counter]>P1[counter]){
  164. printf("\nPlayer 2 it's the wineer");
  165. return;
  166. }
  167. if (P2[counter]==P1[counter] &&Player1sum==Player1sum && counter==1){
  168. printf("\nDraw");
  169. return;
  170. }
  171. }
  172. }