<mosaic.cnfolio.com>
PROGRAM
1. /*START
2.     READ Player 1's Card Total
3.     if they dont have 2 or more than 10 then
4.         Print error message
5.         stop the program
6.
7.     READ the card values for the number of cards player 1 has
8.     if the value are bigger than 10 or smaller than 1 then
9.         print error message
10.         stop the program
11.
12.     READ Player 2's Card Total
13.         if they dont have 2 or more than 10 then
14.         Print error message
15.         stop the program
16.
17.     READ the card values for the number of cards player 2 has
18.     if the value are bigger than 10 or smaller than 1 then
19.         print error message
20.         stop the program
21.
22.     SORT player 1's cards into descending order using a selection sort
23.         set position number to 0
24.         WHILE the position number is one less than the quantity to sort
25.             look in all positions higher than the current position to find the highest number
26.             swap the highest number and the number at the current place
27.             Increase the population by one
28.         END WHILE
29.
30.     SORT Player 2's cards into descending order using a selection sort
31.         set position number to 0
32.         WHILE the position number is one less than the quantity to sort
33.             look in all positions higher than the current position to find the highest number
34.             swap the highest number and the number at the current place
35.             Increase the population by one
36.         END WHILE
37.
38.     Compare Player1's first card and player 2's
39.         if player 1's is bigger then
40.          print player one wins
41.          stop program
42.
43.         if Player 2's is bigger then
44.          print player 2 wins
45.          stop program
46.
47.         if they are on the final card and the value on each card is equal then
48.          print it's a draw
49.          stop program
50.
51.         If non of these are true move to the next card and start comparison again
52. END*/
53.
54. #include <stdio.h>
55. #define MaxSize 9
56. int main(void){
57.
58. //Initialising Variables
59. int Plr1CrdTtl,Plr2CrdTtl;//Player 1 and 2 card totals (i.e. how many cards in hand)
60. int Plr1CrdVls[10]={0};//The values assigned to the array from your card
61. int Plr2CrdVls[10]={0};//""
62. int Plr1CrdPnt,Plr2CrdPnt;//Player 1 and 2 card pointers used to assign the values of the cards to the array
63. int OutPlr1,OutPlr2; //Outside player used in sort
64. int InPlr1,InPlr2;//Inside player used in sort
65. int LowPlr1,LowPlr2;//Lowest player used in sort
66. int TmpSwpVlPlr1,TmpSwpVlPlr2;//Temporary swap value player
67. int NoOfItms=10;//Number of items
68. int CmpPnt=0;//Comparison pointer
69.
70. //Player one card input for card total between 2 and 10
71. scanf("%d", &Plr1CrdTtl);//Reads the input and assigns it to Player 1 card total
72. if((Plr1CrdTtl < 2) || (Plr1CrdTtl > 10))// checks that the user has inputted between 2 and 10 cards
73.    {printf("Error you need between 2 and 10 cards, Player 1\n");//prints and error message
74.    return(0);}
75.
76. //Player one card input for card values into an array
77. for(Plr1CrdPnt = 0; Plr1CrdPnt < Plr1CrdTtl; Plr1CrdPnt++)
78.    {scanf("%d", &Plr1CrdVls[Plr1CrdPnt]);//Assigning card values to positions
79.    if((Plr1CrdVls[Plr1CrdPnt] < 1) || (Plr1CrdVls[Plr1CrdPnt] > 10))//checks that the card values for the array is between 1 and 10
80.       {printf("Enter a number between one and ten, Player 1");// prints error message
81.       return 0;}}
82.
83. //Player two input for card total between 2 and 10
84. scanf("%d",&Plr2CrdTtl);//Reads the input and assigns it to Player 1 card total
85. if(Plr2CrdTtl < 2 || Plr2CrdTtl > 10)//checks that the user has inputted between 2 and 10 cards
86.    {printf("Error you need between 2 and 10 cards, Player 2\n");//prints and error message
87.    return(0);}
88.
89. //Player two card values assigned to the array
90. for(Plr2CrdPnt = 0; Plr2CrdPnt < Plr2CrdTtl; Plr2CrdPnt++)
91.    {scanf("%d",&Plr2CrdVls[Plr2CrdPnt]);//Assigning card values to positions
92.    if((Plr2CrdVls[Plr2CrdPnt] < 1) || (Plr2CrdVls[Plr2CrdPnt] > 10))//checks that the card values for the array is between 1 and 10
93.       {printf("Enter a number between one and ten Player 2");//prints error message
94.       return 0;}}
95.
96.
97. //Selection Sort Player 1
98. for(OutPlr1 = 0; OutPlr1 < (NoOfItms - 1);OutPlr1++)
99.    {LowPlr1 = OutPlr1;
100.    for(InPlr1 = (OutPlr1 + 1); InPlr1 < NoOfItms; InPlr1++)
101.       {if(Plr1CrdVls[InPlr1] > Plr1CrdVls[LowPlr1])
102.          {LowPlr1 = InPlr1;
103.          TmpSwpVlPlr1 = Plr1CrdVls[OutPlr1];
104.          Plr1CrdVls[OutPlr1] = Plr1CrdVls[LowPlr1];
105.          Plr1CrdVls[LowPlr1] = TmpSwpVlPlr1;}}}
106.
107. //Selection sort Player 2
108. for(OutPlr2 = 0; OutPlr2 < (NoOfItms - 1);OutPlr2++)
109.    {LowPlr2 = OutPlr2;
110.    for(InPlr2 = (OutPlr2 + 1);InPlr2 < NoOfItms;InPlr2++)
111.       {if(Plr2CrdVls[InPlr2] > Plr2CrdVls[LowPlr2])
112.          {LowPlr2 = InPlr2;
113.          TmpSwpVlPlr2 = Plr2CrdVls[OutPlr2];
114.          Plr2CrdVls[OutPlr2] = Plr2CrdVls[LowPlr2];
115.          Plr2CrdVls[LowPlr2] = TmpSwpVlPlr2;}}}
116.
117. //Comparison
118. ComparisonCheck :
119. if(Plr1CrdVls[CmpPnt] > Plr2CrdVls[CmpPnt])//if Player 1's current card is bigger than player 2's
120.    {printf("Player 1 Wins!");
121.    return 0;}
122.
123. else if(Plr1CrdVls[CmpPnt] < Plr2CrdVls[CmpPnt])// if player 2's curre t card is bigger than player 1's
124.    {printf("Player 2 Wins!");
125.    return 0;}
126.
127. else if ((Plr1CrdVls[CmpPnt] == Plr2CrdVls[CmpPnt]) && (CmpPnt == MaxSize))// checks if they equal, then they draw
128.    {printf("Draw");
129.    return 0;}
130.
131. else
132. {CmpPnt++;//increments the pointer
133. goto ComparisonCheck;}//jumps to start of the check again
134.
135. return (0);
136. }