<mosaic.cnfolio.com>
PROGRAM
  1. #include <stdio.h>
  2.  
  3. /*
  4. psudo code
  5.  
  6. START
  7.  
  8. how MANY cards does player one have
  9. how MANY cards does player two have
  10.  
  11. WHAT are the VALUES of each card in player ones hand
  12. WHAT are the VALUES of each card in player twos hand
  13. FINISH
  14.  
  15. START
  16. order player ones cards from high to low
  17. order player twos cards from high to low
  18.  
  19. WHAT is player ones highest number card
  20. WHAT is player twos highest number card
  21.  
  22. IF player ones first card value is higher then players twos
  23.    THEN player one wins
  24.       ENDIF
  25.  
  26. IF player twos first card value is higher than players ones,
  27.    THEN player two wins
  28.       ENDIF
  29.    
  30. IF players ones first card is lower than players twos card
  31.    THEN player two wins
  32.       ENDIF
  33.    
  34. IF player twos first card is lower than player ones card
  35.    THEN player one wins
  36.       ENDIF
  37.  
  38. IF player ones first card is equal to players twos first card
  39.    THEN the round is a draw
  40.       THEN the next card is drawn
  41.       ENDIF
  42.    
  43. IF payers ones second card is higher than player twos
  44.    THEN player one wins
  45.          ENDIF
  46.  
  47. IF player ones second card is lower than player twos
  48.    THEN player two loses
  49.       ENDIF
  50.  
  51. IF player twos second card is higher than player ones
  52.    THEN player two wins
  53.       ENDIF
  54.      
  55. IF player twos second card is lower than player ones
  56.    THEN player two loses
  57.       ENDIF
  58.  
  59. IF both players have equal cards again
  60.    THEn the next card is used
  61.       ENDIF
  62.      
  63. IF all cards are a draw
  64.    THEN the game is a draw
  65.       ENDIF
  66.  
  67. END
  68.  
  69.  
  70. */
  71.  /*
  72. read in number of cards for A
  73. read in cards put numbers in array
  74. bubble sort function
  75. repeat 1-3 for B
  76. higher or lower and who wins function
  77. */
  78.  
  79.  
  80. int main( void )
  81. {
  82.   int   PlayerACards[10];
  83.   int   PlayerBCards[10];
  84.   int   AmountOfCardsA, AmountOfCardsB, i, j, Temp, Winner;
  85.   Winner = 1;
  86.  
  87.   /* Read in amount of player 1's casrds */ 
  88.   scanf("%d", &AmountOfCardsA);
  89.   printf(" theres %d cards for player 1 in order ", AmountOfCardsA);
  90.   /* Read in player 1's cards */
  91.   for ( i = 0; i < AmountOfCardsA; i++)
  92.   {
  93.     scanf("%d", &PlayerACards[i]);
  94.   }
  95.   /* Order player 1's cards */
  96.   for ( j = 0; j < AmountOfCardsA ; j++){
  97.    
  98.     for ( i = 0 ; i < (AmountOfCardsA - 1) ; i++){
  99.      
  100.       if ( PlayerACards[i] < PlayerACards[i+1] )
  101.       {
  102.         Temp = PlayerACards[i];
  103.         PlayerACards[i] = PlayerACards[i+1];
  104.         PlayerACards[i + 1] = Temp;
  105.       }
  106.     }
  107.    
  108.    
  109.   }
  110.  
  111.   /* Display player 1's ordered cards */
  112.   for ( i = 0; i < AmountOfCardsA; i++)
  113.   {
  114.    
  115.     printf("%d ", PlayerACards[i]);
  116.   }
  117.  
  118.   /* read in amount of player 2's cards */
  119.   scanf("%d", &AmountOfCardsB);
  120.   printf(" theres %d for player 2 cards in order ", AmountOfCardsB);
  121.   /* read in player 2's cards */
  122.   for ( i = 0; i < AmountOfCardsB; i++)
  123.   {
  124.     scanf("%d", &PlayerBCards[i]);
  125.   }
  126.   /* Order player 2's cards */
  127.   for ( j = 0; j < AmountOfCardsB ; j++){
  128.    
  129.     for ( i = 0 ; i < (AmountOfCardsB - 1) ; i++){
  130.      
  131.       if ( PlayerBCards[i] < PlayerBCards[i+1] )
  132.       {
  133.         Temp = PlayerBCards[i];
  134.         PlayerBCards[i] = PlayerBCards[i+1];
  135.         PlayerBCards[i + 1] = Temp;
  136.       }
  137.     }
  138.    
  139.    
  140.   }
  141.  
  142.   /* display player 2's ordered cards */
  143.   for ( i = 0; i < AmountOfCardsB; i++)
  144.   {
  145.    
  146.     printf("%d ", PlayerBCards[i]);
  147.   }
  148.   /* Find winner */
  149.   /*if (AmountOfCardsA >= AmountOfCardsB){*/
  150.   for(i=0; i<10; i++){
  151.     if (PlayerACards[i]>PlayerBCards[i]){
  152.       Winner = 0;
  153.       break;
  154.     }
  155.     else if (PlayerACards[i]<PlayerBCards[i]){
  156.       Winner=2;
  157.       break;
  158.     }   
  159.   }
  160.  
  161.  
  162.   /* Output winner*/
  163.   if (Winner < 1){
  164.     printf("Player 1 wins");
  165.   }
  166.   else if (Winner > 1 ){
  167.     printf("Player 2 wins");
  168.   }
  169.   else if (0 < Winner < 2){
  170.     printf("Its a draw");
  171.   }
  172.  
  173. }