<mosaic.cnfolio.com>
PROGRAM
  1. /* Final V 3.2 */
  2. /* the game is working just fine with no errors */
  3.  
  4.  
  5. /*
  6. START
  7.  
  8. Take input for the number of cards each player has
  9. If number is not between 2-10
  10.      Show error
  11. Take input for the cards each player has
  12. If a card is higher than 10
  13.     Show error
  14. Arrange the cards in descending order
  15. Take the first card of each player
  16. If they are equal
  17.     Then
  18.         If there are more cards
  19.             Move onto the next set of cards
  20.         Else
  21.           Declare a draw
  22.     Else
  23.         Declare the player with the highest card winner
  24. END
  25. */
  26.  
  27.  
  28. #include <stdio.h>
  29. #define MAX_SIZE 10
  30.  
  31. int main()
  32. {
  33.    int p1c[MAX_SIZE];
  34.    int p2c[MAX_SIZE];
  35.    int p1noc;
  36.    int p2noc;
  37.    int i, j, temp1;
  38.    int o, k, temp2;
  39.    int r, e;
  40.    int end=0;
  41.  
  42.    /* ++++++++++ P1 side of things ++++++++++ */
  43.    /* Input number of cards for p1 */
  44.    scanf("%d", &p1noc);
  45.    
  46.    if ( 2>p1noc || p1noc>10 ){
  47.       printf("A Player must have 2-10 cards or the game won't run");
  48.       return 0;
  49.    }
  50.    
  51.  
  52.    /* Input the cards p1 has */
  53.    for(i=0; i<p1noc; i++)
  54.    {
  55.        scanf("%d", &p1c[i]);
  56.    }
  57.  
  58.    for(i=0; i<p1noc; i++)
  59.    {
  60.        /*
  61.         * Place the currently selected element p1noc[i]
  62.         * to its correct place.
  63.         */
  64.        for(j=i+1; j<p1noc; j++)
  65.        {
  66.            /*
  67.             * Swap if currently selected array element
  68.             * is not at its correct position.
  69.             */
  70.            if(p1c[i] < p1c[j])
  71.            {
  72.                temp1   = p1c[i];
  73.                p1c[i] = p1c[j];
  74.                p1c[j] = temp1;
  75.            }
  76.        }
  77.    }
  78.    
  79.    /* ++++++++++ P1 side of things ++++++++++ */
  80.    /* ++++++++++ P2 side of things ++++++++++ */
  81.    
  82.    /* Input number of cards for p2 */
  83.    scanf("%d", &p2noc);
  84.    
  85.    if ( 2>p2noc || p2noc>10 ){
  86.       printf("A Player must have 2-10 cards or the game won't run");
  87.       return 0;
  88.    }
  89.  
  90.    /* Input the cards p2 has */
  91.    for(o=0; o<p2noc; o++)
  92.    {
  93.        scanf("%d", &p2c[o]);
  94.    }
  95.  
  96.    for(o=0; o<p2noc; o++)
  97.    {
  98.        /*
  99.         * Place the currently selected element p2noc[i]
  100.         * to its correct place.
  101.         */
  102.        for(k=o+1; k<p2noc; k++)
  103.        {
  104.            /*
  105.             * Swap if currently selected array element
  106.             * is not at its correct position.
  107.             */
  108.            if(p2c[o] < p2c[k])
  109.            {
  110.                temp2   = p2c[o];
  111.                p2c[o] = p2c[k];
  112.                p2c[k] = temp2;
  113.            }
  114.        }
  115.    }
  116.    /* ++++++++++ P2 side of things ++++++++++ */
  117.    
  118.    /* print the number of cards p1 has */
  119.    printf("\n\tPlayer 1 has (%d) card/s..,", p1noc);
  120.    /* Print the sorted array */
  121.    printf("\n\tThe cards Player 1 has: ");
  122.    for(i=0; i<p1noc; i++)
  123.    {
  124.        printf("%d\t", p1c[i]);
  125.    }
  126.    
  127.    /* print the number of cards p2 has */
  128.    printf("\n\tPlayer 2 has (%d) card/s..,", p2noc);
  129.    /* Print the sorted array */
  130.    printf("\n\tThe cards Player 2 has: ");
  131.    for(o=0; o<p2noc; o++)
  132.    {
  133.        printf("%d\t", p2c[o]);
  134.    }
  135.    
  136.    int v = 1;
  137.    
  138.    if (p1noc>p2noc){
  139.       end=p1noc;
  140.    }
  141.    else{
  142.       end=p2noc;
  143.    }
  144.    
  145.  
  146.  
  147.    
  148.    
  149.    for (v = 0; ((v != p1noc) && (v != p2noc)) || ((v < p2noc) || (v < p1noc)); v++ ){
  150.       
  151.       r=v+1;
  152.       if (p1c[v] > p2c[v]){
  153.          printf("\n\tPlayer 1 won the game in Round %d",r);
  154.          
  155.          break;
  156.          
  157.       }
  158.       if (p1c[v] < p2c[v]){
  159.          printf("\n\tPlayer 2 won the game in Round %d",r );
  160.          
  161.          break;
  162.          
  163.       }
  164.      
  165.       if (p1c[v] == p2c[v]){
  166.             printf(" \n\tRound %d is a drow ",r);
  167.            
  168.       }
  169.       if (v==end-1){
  170.          printf ("\n\tthe game endded in a draw");
  171.          break;
  172.       }
  173.      
  174.      
  175.    }
  176.    
  177.  
  178. return 0;
  179. }