<mosaic.cnfolio.com>
PROGRAM
1. /*
2. Pseudo Code
3.
4. START
5. Player 1, Input the Quantity of Cards (2-8 cards)
6. Player 2, Input the Quantity of Cards (2-8 cards)
7. Player 1, Input Cards between 1-10
8. Player 2, Input Cards between 1-10
9.
10. Get Cards from Player 1
11. Get Cards from Player 2
12.
13. WHILE all Players must have cards
14.
15. THEN Sort Cards Highest to Lowest
16.
17. IF Player 1 Card Greater than Player 2 Card
18.    THEN Player 1 Wins
19.
20. ELSE
21.
22.   Player 1 Card less than Player 2 Card
23.    THEN Player 2 Wins
24.
25.   IF Player 1's Card is = Player 2's Card
26.    THEN
27.          Player 1 and Player 2 = Draw
28.
29.   END WHILE
30.
31.   END
32.
33.
34.
35. */
36.
37.  #include <stdio.h>
38.
39.
40.
41. int main(void)
42. {
43.
44. int  x, y, z;
45. int TotalPlayer1Cards;
46. int Player1 [10] = {0};/* The Cards Player 1 can use*/
47. int TotalPlayer2Cards; 0 ;
48. int Player2 [10] = {0}; /* The Cards Player 2 can use */
49.
50.
51.
52. /* The amount of Cards player 1 inputs */
53.
54. scanf("%d", &TotalPlayer1Cards);
55.    for(x = 0; x < TotalPlayer1Cards; x++)
56.       { scanf("%d", &Player1 [x]);
57.       }
58.
59. /* The amount of Cards Player 2 Inputs */
60. scanf("%d", &TotalPlayer2Cards);
61.    for(x = 0; x < TotalPlayer2Cards; x++)
62.       { scanf("%d", &Player2 [x]);
63.       }
64.
65. /* Data Validation */
66.
67.
68. if(TotalPlayer1Cards > 10 || TotalPlayer1Cards < 2) {
69.    printf("Player 1 has inputted too many cards!");
70.    return 0;
71.    } /* This checks whether Player 1 has put cards between 2 and 10 */
72.
73.
74. if(TotalPlayer2Cards > 10 ||TotalPlayer2Cards < 2) {
75.    printf("Player 2 has inputted too many cards!");
76.    return 0;
77.    } /* This checks whether Player 2 has put cards between 2 and 10 */
78.
79. for(x = 0; x < TotalPlayer1Cards; x++) {
80.    if(Player1[x] < 1 || Player1[x] > 10) {
81.       printf("Player 1 has not entered the correct values specified");
82.       return 0;
83.      }
84.   } /* This checks whether Player1 has entered numbers between 1 and 10 */
85.
86.      for(x = 0; x < TotalPlayer2Cards; x++) {
87.    if(Player2[x] < 1 || Player2[x] > 10) {
88.       printf("Player 2 has not entered the correct values specified");
89.       return 0;
90.       }
91.       }
92.       /* This checks whether Player2 has entered numbers between 1 and 10 */
93.
94.
95.
96.      for(x = 0; x < TotalPlayer1Cards; x ++) {
97.        for(y = 0; y <TotalPlayer1Cards; y++) {
98.                if(Player1[y + 1] > Player1[y]) {
99.
100.                         z = Player1[y];
101.                         Player1[y] = Player1 [y + 1];
102.                         Player1[y + 1] = z;
103.
104.                        }
105.                        }
106.                        }/* Sorts out Player 1's Cards */
107.
108.           for(x = 0; x < TotalPlayer2Cards; x ++) {
109.        for(y = 0; y <TotalPlayer2Cards; y++) {
110.                if(Player2[y + 1] > Player2[y]) {
111.
112.                         z = Player2[y];
113.                         Player2[y] = Player2[y + 1];
114.                         Player2[y + 1] = z;
115.
116.                        }
117.                        }
118.                        }/* Sorts out Player 2's Cards */
119.
120.    /* This compares the cards in each of the players hands */
121.
122.
123.  for(x = 0; x < 10; x++) {
124.
125.     /* This checks if Player 1 Wins*/
126.     if(Player1[x] > Player2[x]) {
127.         printf("Player 1 is the winner!");
128.         return 0;
129.     }
130.
131.
132.     /* This checks if Player 2 Wins*/
133.     if(Player1[x] < Player2[x]) {
134.         printf("Player 2 is the winner!");
135.         return 0;
136.     }
137. }
138.
139. /* This occurs when both of the players draw */
140.
141. printf("Draw!");
142.      }