<mosaic.cnfolio.com>
PROGRAM
  1. /* Pseudo code:
  2. START
  3. Input amount of cards for Player 1
  4. WHILE amount is not a number between 2 and 10
  5.    Output error message "Please enter a number between 2 and 10" 
  6. END WHILE
  7. Input values of Player 1's cards
  8. WHILE values are not between 1 and 10
  9.    Output error message "Please enter numbers between 1 and 10"
  10. END WHILE
  11.  
  12. Input amount of cards for Player 2
  13. WHILE amount is not a number between 2 and 10
  14.    Output error message "Please enter a number between 2 and 10" 
  15. END WHILE
  16. Input values of Player 2's cards
  17. WHILE values are not between 1 and 10
  18.    Output error message "Please enter numbers between 1 and 10"
  19. END WHILE
  20.  
  21. Sort Player 1's cards using for loops:
  22. FOR numbers less than amount of cards, run code then add 1 to the number
  23.    FOR numbers + 1 less than amount of cards, run code then add 1 to the number
  24.       IF first element in array is less than second element
  25.          THEN
  26.             Assign value of first element to temporary variable
  27.             Change value of first element to value of second element
  28.             Change value of second element to value of temp variable
  29.  
  30. Sort Player 2's cards using for loops:
  31. FOR numbers less than amount of cards, add 1 to the number
  32.    FOR numbers + 1 less than amount of cards, add 1 to the number
  33.       IF first element in array is less than second element
  34.          THEN
  35.             Assign value of first element to temporary variable
  36.             Change value of first element to value of second element
  37.             Change value of second element to value of temp variable
  38.            
  39. Decide winner:
  40. FOR values less than 11 (max array size)
  41.    IF Player 1's value is greater than Player 2's
  42.       THEN
  43.          Output "Player 1 wins!"
  44.          Exit program
  45.       ELSE IF Player 2's value is greater than Player 1's
  46.          THEN
  47.             Output "Player 2 Wins!"
  48.             Exit program
  49.       ELSE IF Both Player 1and Player 2's values are 0
  50.          THEN
  51.             Output "Its a draw!"
  52.             Exit program
  53.       ELSE IF The values are equal
  54.          THEN
  55.             Continue the for loop
  56.    END IF
  57.  
  58. END */
  59.  
  60. #include <stdio.h>
  61. #include <stdlib.h>
  62.  
  63. int main()
  64. {
  65.     int player1_amount = 0;    /* Declaring amount variables for user entry */
  66.     int player2_amount = 0;   
  67.     int a, b; /* These are random values used in for loops */
  68.  
  69.     /* P1 Amount of Cards */   
  70.     scanf("%d", &player1_amount); /* Takes user input and ouputs error if an incorrect number is entered */
  71.     while(player1_amount < 2 || player1_amount > 10)
  72.     {
  73.         printf("\nError. Please enter a number from 2 to 10.");
  74.         return 0;
  75.     }
  76.    
  77.     int player1_values[player1_amount + 1]; /* Creates an array 1 size bigger than the amount of cards. This means the final element will always be 0, and allows the program to calculate a draw */
  78.  
  79.  
  80.    /* P1 Card Values */   
  81.    for(a = 0; a < player1_amount ; a++) /* Takes user input and ouputs error if an incorrect number is entered */
  82.     {    
  83.           scanf("%d", &player1_values[a]);   
  84.          
  85.     }
  86.     for(a = 0; a < player1_amount ; a++)
  87.     {
  88.       while(player1_values[a] < 1 || player1_values[a] > 10)
  89.         {
  90.             printf("Error. Please enter values from 1 to 10.");
  91.             return 0;
  92.         }
  93.     }
  94.      
  95.      
  96.     /* P2 Amount of Cards */   
  97.     scanf("%d", &player2_amount); /* Takes user input and ouputs error if an incorrect number is entered */
  98.     while(player1_amount < 2 || player1_amount > 10)
  99.     {
  100.         printf("\nError. Please enter a number from 2 to 10.");
  101.         return 0;
  102.     }
  103.    
  104.     int player2_values[player2_amount + 1]; /* Creates an array 1 size bigger than the amount of cards. This means the final element will always be 0, and allows the program to calculate a draw */
  105.    
  106.    
  107.     /* P2 Card Values */
  108.     for(a = 0; a < player2_amount ; a++) /* Takes user input and ouputs error if an incorrect number is entered */
  109.     {
  110.         scanf("%d", &player2_values[a]);
  111.     }
  112.     for(a = 0; a < player2_amount ; a++)
  113.     {
  114.         while(player2_values[a] < 1 || player2_values[a] > 10)
  115.         {
  116.             printf("Error. Please enter values from 1 to 10.");
  117.             return 0;
  118.         }
  119.     }
  120.    
  121.    
  122.     /* Orders P1 Values Descending */
  123.     int tempvalue;   
  124.     for(a = 0; a < player1_amount; a++)
  125.     {
  126.         for(b = a + 1; b < player1_amount; b++)
  127.         {
  128.             if(player1_values[a] < player1_values[b])
  129.             {
  130.                 tempvalue = player1_values[a];
  131.                 player1_values[a] = player1_values[b];
  132.                 player1_values[b] = tempvalue;
  133.             }
  134.         }
  135.     }   
  136.    
  137.  
  138.     /* Orders P2 Values Descending */
  139.     for(a = 0; a < player2_amount; a++)
  140.     {
  141.         for(b = a + 1; b < player2_amount; b++)
  142.         {
  143.             if(player2_values[a] < player2_values[b])
  144.             {
  145.                 tempvalue = player2_values[a];
  146.                 player2_values[a] = player2_values[b];
  147.                 player2_values[b] = tempvalue;
  148.             }
  149.         }
  150.     }   
  151.    /* These order scripts swap the values of adjacent numbers if the first one is smaller, and continue through the whole array */ 
  152.    
  153.    
  154.    /* Deciding Winner */
  155.     for(a = 0; a < 11; a++)
  156.     {
  157.         if(player1_values[a] > player2_values[a]) /* Player 1 wins if their value is greater than player 2's */
  158.         {
  159.             printf("\nPlayer 1 wins!\n");
  160.             return 0;
  161.         }
  162.         else if(player1_values[a] < player2_values[a]) /* Player 2 wins if their value is greater than player 1's */
  163.         {
  164.             printf("\nPlayer 2 wins!\n");
  165.             return 0;
  166.         }
  167.         else if(player1_values[a] == 0 && player2_values[a] == 0) /* If all numbers in the array are the same, the only elements left are 0, so if both arrays have a 0, the game is a draw */
  168.         {
  169.             printf("\nIt's a draw!\n");
  170.             return 0;
  171.         }
  172.         else if(player1_values[a] == player2_values[a]) /* If the values are the same, the for loop continues and checks the next values */
  173.         {
  174.             continue;
  175.         }
  176.     }
  177.  
  178. }