<mosaic.cnfolio.com>
PROGRAM
1. /*----------------------Pseaudo Code----------------------------*/
2.
3.
4. /*Start
5. Obtain Player 2_Hand
6. Obtain Player 2_Hand
7.
8. Check if inputs are valid
9. Sort Player 1’s hand highest to lowest
10. Sort player 2’s hand highest to lowest
11.
12. WHILE player has cards in hand
13. Compare the highest cards
14. IF P1 > P2
15. P1 win
16.
17. ELSE
18. P2 Win
19.
20. ELSE IF P1 = P2
21. Check next highest card in each hand.
22. IF no cards are apparent DRAW
23. END WHLE
24. END*/
25.
26.
27.
28. #include <stdio.h>
29. int main (void)
30. {
31.       /*Variables for Program*/
32. int i, j, temp, temp2;
33. int PL1Quantity = 0; /*The total number cards player 1 has*/
34. int PL1Values = {0}; /*Variables to store the number of cards in player 1s hand*/
35. int PL2Quantity = 0; /*The total number of cards player 2 has*/
36. int PL2Values = {0}; /*Variables to store the number of cards in player 1s hand/*
37.
38.
39.       /*inputs*/
40. scanf("%d", &PL1Quantity); /* Scan the amount of cards in the users hand */
41. for(i = 0; i < PL1Quantity; i++) {
42. scanf("%d", &PL1Values[i]);
43.         }
44.
45.
46. scanf("%d", &PL2Quantity); /* Scan the amount of cards in the users hand */
47. for(i = 0; i <PL2Quantity; i++) {
48. scanf("%d", &PL2Values[i]);
49.
50. }
51.
52.
53.       /*Player 1 error check*/
54.
55. if(PL1Quantity < 2 || PL1Quantity > 10) {
56. printf("Player 1 has inputted an invalid quantity of cards. Solution: Enter in a quantity between 2 and 10.");
57.
58.     return 0;
59. }
60.
61.       /*Player 2 error check*/
62. if(PL2Quantity < 2 || PL2Quantity > 10) {
63. printf("Player 2 has inputted an invalid quantity of cards. Solution: Enter in a quantity between 2 and 10.");
64.
65.     return 0;
66. }
67.
68.      /* Player 1s Array check */
69.
70. for (i = 0; i < PL1Quantity; i++)
71.    {
72. if (PL1Values[i] < 1 || PL1Values[i] > 10)
73.    {
74. printf("Player 1 has inputted the incorrect values into their hand. Solution: Enter in a value between 1 and 10.");
75.        return 0;
76.
77.   }
78. }
79.      /* Player 2s Array check */
80.
81. for (i = 0; i < PL2Quantity; i++)
82.    {
83. if (PL2Values[i] < 1 || PL2Values[i] > 10)
84.    {
85. printf("Player 2 has inputted the incorrect values into their hand. Solution: Enter in a value between 1 and 10.");
86.        return 0;
87.   }
88. }
89.
90.      /* Sorting system */
91. for (i = 0; (i <= PL1Quantity); i++)
92.     {
93. for (j = 0; (j <= PL1Quantity - 1); j++)
94.    {
95. if (PL1Values[j + 1] > PL1Values[j])
96.        {
97. temp2 = PL1Values[j];
98. PL1Values[j] = PL1Values[j + 1];
99. PL1Values[j + 1] = temp2;
100.        }
101.    }
102. }
103.
104.
105.
106. for (i = 0; (i <= PL2Quantity); i++)
107.     {
108. for (j = 0; (j <= PL2Quantity - 1); j++)
109.    {
110. if (PL2Values[j + 1] > PL2Values[j])
111.        {
112. temp2 = PL2Values[j];
113. PL2Values[j] = PL2Values[j + 1];
114.          PL2Values[j + 1] = temp2;
115.        }
116.    }
117. }
118.
119.     /*outcome*/
120. for(i = 0; i < 10; i++) {
121.
122.
123. if(PL1Values[i] > PL2Values[i]) { /*If player 1 has a higher value card than player 2 then player 1 wins*/
124. printf("Player 1 Wins!");
125.
126.     return 0;
127. }
128. if(PL2Values[i] > PL1Values[i]) { /*If player 1 has a higher value card than player 2 then player 1 wins*/
129. printf("Player 2 Wins!")
130.
131.     return 0;
132. }
133. }
134. printf("It's a draw!");
135.
136.
137. }