<mosaic.cnfolio.com>
PROGRAM
  1. /*
  2. pseudocode
  3.  
  4. Start
  5.  
  6. There will be 2 players in the game - PlayerA and PlayerB
  7.  
  8. Welcome message will be displayed in the screen
  9.  
  10. player A  numbers of card will be asked
  11.  
  12. number of cards of Player A has to be enter
  13.  
  14. player A cards number will be asked
  15.  
  16. cards number of player A has to be enter
  17.  
  18. player B numbers of card will be asked
  19.  
  20. number of cards of player B has to enter
  21.  
  22. player B cards number will be asked
  23.  
  24. cards number of player A has to enter
  25.  
  26. run the program
  27.  
  28. in output, all the cards will be displayer from higher to lower
  29.  
  30. the player with the higher card will win
  31.  
  32. if both has the same higher cards, higher card will be cancel and second highest card will be compare.
  33.  
  34. if both has a same number of cards and cards number, it will shows draw in a display.
  35.  
  36. if the input number are wrong, the system will show the error message.
  37. */
  38.  
  39. //program coding starts from here
  40.  
  41. #include <stdio.h>
  42.  
  43. #define max 10
  44. //max cards are 10
  45. int main(void)
  46.  
  47. {
  48.       
  49. int playerA[max], playerB[max]; //Lining up the Number of cards
  50. int s,o,p,q,r,sort,win;               
  51. printf("welcome to the card game");
  52.      
  53. //input of number of cards of player A
  54.   printf("\nPlayer A, type the numbers of card you have.");
  55.   scanf("%d",&p);
  56.      
  57. //each player must have cards from 2 to 10
  58.   if(p<2 || p>10){
  59.   printf("\n\nPlayer A, you have %d cards on your hand, \nYou can only have 2 to 10 Cards",p);
  60.   return(0);
  61.   scanf("%d",&p); }
  62.      
  63. //input of cards number
  64.   printf("\nPlayer A, type your Cards number");
  65.      
  66.   for(s=0; s<p; s++){
  67.   scanf("%d",&playerA[s]);
  68.          
  69. //Only cards from 1 to 10 number should be used
  70.   if(playerA[s]<1 || playerA[s]>10){
  71.   printf("\nCards need to be between 1 to 10");
  72.   scanf("%d",&playerA[s]);
  73.   }
  74.   }
  75.      
  76.      
  77. //input of number of cards of player B
  78.   printf("\nPlayer B, type the numbers of card you have");
  79.   scanf("%d",&q);
  80.   if(q<2 || q>10){
  81.   printf("\n\nPlayer B, you have %d cards on your hand, \nYou can only have 2 to 10 Cards",q);
  82.   scanf("%d",&q);
  83.   }
  84.  
  85. //Taking input PlayerB Cards
  86.   printf("\nPlayerB, type your cards number");
  87.   for(s=0; s<q; s++)
  88.   {
  89.  
  90.   scanf("%d",&playerB[s]);
  91.   if(playerB[s]<1 || playerB[s]>10){
  92.   printf("\nCards must be in between 1 to 10");
  93.   scanf("%d",&playerB[s]);
  94.   }
  95.   }
  96.  
  97.  //Sorting cards from highest to lowest of Player A
  98.    for(s=0; s<p; s++)
  99.   {
  100.          
  101.    for(o=s+1; o<p; o++){
  102.             
  103.    if(playerA[s] < playerA[o]){
  104.            
  105.    sort = playerA[s];
  106.    playerA[s] = playerA[o];
  107.    playerA[o]=sort;
  108.    }
  109.    }
  110.    }
  111.      
  112.      
  113.      
  114. //Sorting cards from highest to lowest of Player B
  115.    for(s=0; s<q; s++)
  116.    {
  117.          
  118.    for(o=s+1; o<q; o++){
  119.             
  120.    if(playerB[s] < playerB[o]){
  121.            
  122.    sort = playerB[s];
  123.    playerB[s] = playerB[o];
  124.    playerB[o]=sort;
  125.    }
  126.    }
  127.    }
  128.      
  129.      
  130. //player A Cards
  131.      
  132.    printf("\n\nPlayer A has %d cards: ",p);
  133.    for(s=0; s<p; s++)
  134.    {
  135.    printf("%d ",playerA[s]);
  136.    }
  137.      
  138. //Player B Cards
  139.      
  140.    printf("\nPlayer B has %d cards: ",q);
  141.    for(s=0; s<q; s++)
  142.    {
  143.    printf("%d ",playerB[s]);
  144.    }
  145.  
  146.  //highest numbers of cards
  147.      
  148.    if(p>q){
  149.    r = p;
  150.    }
  151.    
  152.    else if(q>p){
  153.    r = q;
  154.    }
  155.    
  156.    else{
  157.    r = p;
  158.    }
  159.      
  160.    for(s=max; s>=p; s--){
  161.    playerA[s]=0;
  162.    }
  163.      
  164.    for(s=max; s>=q; s--){
  165.    playerB[s]=0;
  166.    }
  167.      
  168.      
  169. // Deciding the winner
  170.      
  171.    for(s=0; s<r; s++)
  172.    {
  173.    
  174.    if(playerA[s] > playerB[s])
  175.    {
  176.    
  177.    win = 1; //decide 1 player1 win             
  178.    break;
  179.    }
  180.            
  181.    else if(playerA[s] < playerB[s])
  182.             {
  183.    win = 2; //decide 2 player1 win
  184.    break;
  185.    }
  186.    }
  187.      
  188.    printf("\n ");
  189.    if(win == 1){
  190.    printf("\n     >  Player A win  <");
  191.    }
  192.      
  193.    else if(win == 2){
  194.    printf("\n     >  Player B win  <");
  195.       }
  196.      
  197.    else{
  198.    printf("\n      >    Draw    <");
  199.       }
  200.      
  201.    printf("\n");
  202.      
  203. }