<mosaic.cnfolio.com>
PROGRAM
  1. /* Coursework 1 card game*/
  2. /*
  3. Start
  4. input how many cards player 1 has
  5. if player 1 inputs less than 2 cards
  6. print error, input more cards
  7. else if player 1 inputs more than 10 cards
  8. print error, input less cards
  9. store the input variable
  10. input player 1's cards values
  11. process the cardvalues in order from highest to lowest
  12. print player 1's cards in order
  13. input how many cards player 2 has
  14. if player 2 inputs less than 2 cards
  15. print error, input more cards
  16. else if player 2 inputs more than 10 cards
  17. print error, input less cards
  18. store the input variable
  19. input player 2's card values
  20. process the card values in order from highest to lowest
  21. print player 2's ordered cards
  22. if player 1 has less cards than player 2 then that is the maximum times the cards will be compared
  23. else if player two has less cards than player 1 then that will be the maximum times the cards will be compared
  24. if player 1's card> player 2's card,
  25. print player 1 wins
  26. else if player 2's cards> player 1's card
  27. print player 2 wins
  28. else if player 1's card=player 2's card
  29. print its a draw
  30. end
  31. */
  32.  
  33. #include <stdio.h>
  34. int main( void ){
  35.     int i;
  36.     int j;
  37.     int temp,a,b,c;    /*This section states the variables*/
  38.     int s[10],r[10];
  39.     int num;
  40.     int k;
  41.    
  42.    
  43.  
  44. printf("How many cards does player 1 have?\n"); /*this is commanding the user to input the quantity on cards into the compiler*/
  45. scanf("%d",&i);
  46.  
  47. if(i<2)
  48. {
  49. printf("Error, increase the amount of cards enetered\n");
  50. return 1; /* This section ensures the user inputs the correct amount of cards*/
  51. }
  52. else if (i>10)
  53. {
  54. printf("Error, decrease the amount of cards entered\n");
  55. return 1;
  56. }
  57.  
  58.  
  59.  
  60. c=0;
  61. do{
  62.     printf("Enter player 1's card values %d\n", c); /*This function arranges the cards in order high to low*/
  63.     scanf("%d", &s[c]);
  64.     c=c+1;
  65. }while (c<i);
  66.  
  67. b=0;
  68.  do {
  69.      a=0;
  70.      do{
  71.          if(s[a]<s[a+1]) {
  72.              temp=s[a];
  73.              s[a]=s[a+1];
  74.              s[a+1]=temp;
  75.          }
  76.          a=a+1;
  77.      }while(a<i-1);
  78.      b=b+1;
  79.  }while (b<50);
  80.  
  81.  c=0;
  82. printf("ordered\n");
  83. do{
  84.     printf("%d\n", s[c]);
  85.     c=c+1;
  86. }while(c<i);
  87.  
  88. printf("How many cards does player 2 have?\n"); /*This makes the user input the cards values*/
  89. scanf("%d",&j);
  90.  
  91. if(j<2)
  92. {
  93. printf("Error, increase the amount of cards entered\n"); /*This makes the user input the correct amount of cards*/
  94. }
  95. else if (j>10)
  96. {
  97. printf("Error, decrease the amount of cards entered\n");
  98. }
  99.  
  100.  
  101. c=0;
  102. do{
  103.     printf("Enter player 2's card values %d\n", c); /*this arranges player 2's cards in order*/
  104.     scanf("%d", &r[c]);
  105.     c=c+1;
  106. }
  107. while (c<j);
  108.  
  109. b=0;
  110.  do {
  111.      a=0;
  112.      do{
  113.          if(r[a]<r[a+1]) {
  114.              temp=r[a];
  115.              r[a]=r[a+1];
  116.              r[a+1]=temp;
  117.          }
  118.          a=a+1;
  119.      }while(a<j-1);
  120.      b=b+1;
  121.  }while (b<50);
  122.  
  123.  c=0;
  124. printf("ordered\n");
  125. do{
  126.     printf("%d\n", r[c]);
  127.     c=c+1;
  128. }while(c<j);
  129.  
  130. if(i<j)
  131. {
  132. k=i;
  133. }
  134. else{
  135. k=j;}
  136.  
  137. c=0;
  138.  
  139. do{       
  140.  
  141. if (s[c]>r[c])
  142. {
  143.     printf("Player 1 wins!\n"); /*the statements below produce an output telling the user whatplayer won*/
  144.     return 0;
  145. }
  146. else if (r[c]>s[c])
  147. {
  148.     printf("Player 2 wins!\n");
  149.     return 0;
  150. }
  151. else if (s[c]==r[c])
  152. {
  153.     printf("Its a draw on card %d\n", c);
  154.     if (c==k-1) {
  155.     if(j>i){
  156.     printf("Player 2 wins!\n");
  157.     return 0; }  /*The return 0 function stops the programme aftera player has won*/
  158.     else if (i>j){
  159.     printf("Player 1 wins!\n");
  160.     return 0;
  161.     }
  162.     else {
  163.     printf("Its a draw\n");
  164.     return 0;
  165.     }
  166.    
  167. }
  168. }
  169. c=c+1;}
  170. while(c<k);} /*This function ends the whole programme*/