<mosaic.cnfolio.com>
PROGRAM
1. /*PSUEDO CODE
2. --Start
3. --player1 TOM
4. --player2 JERRY
5. --assign TOM with 2 to 10 cards
6. --  IF
7. --  the card  is less than 2 or more than 10 then
8. --  display ERROR allowed to have only 2 to 10 cards
9.
10. --assign JERRY with 2 to 10 cards
11. --  IF
12. --  the card is less than 2 or more than 10 then
13. --  display ERROR allowed to have only 2 to 10 cards
14.
15. --assign TOM with 1-10 numbered cards based on the quantity of their hand
16. --  IF
17. --  the number is less than 1 or more than 10 then
18. --  display ERROR cards should be only between 1 to 10 number
19.
20. --assign JERRY with 1-10 numbered cards based on the quantity of their hand
21. --  IF
22. --  the number is less than 1 or more than 10 then
23. --  display ERROR cards should be only between 1 to 10 number
24.
25. --sort TOM cards from highest to lowest
26. --sort JERRY cards from highest to lowest
27.
28. --sort who got the highest number between TOM and JERRY
29. --  IF
30. --  (TOM has higher number than JERRY) then winner =1
31. --  ELSE IF
32. --  (TOM has lower number JERRY) then winner=2
33.
34. --sort out the winner
35. --who have more cards in their card after one player is out of cards
36.
37. --sort who is the winner
38. --  IF
39. --  winner == 1
40. --  display *** TOM win the game ***
41.
42. --  ELSE IF
43. --  winner == 2
44. --  display *** JERRY win the game ***
45. --  ELSE
46. --  *** DREAW ***
47. */
48.
49.
50.
51.
52.
53. #include <stdio.h>
54. #define MAXIMUMCARD          10
55.
56. int main(void)
57. {
58.
59. int  TOM[MAXIMUMCARD],   JERRY[MAXIMUMCARD];         /*array of number of cards*/
60.
61. int  A, B, H, X, Y, trash, winner ;
62.
63.
64. printf("*** welcome to the card game lads ***");
65.
66. printf("\n\n TOM enter the number of cards");   /*input of number of cards for TOM*/
67.
68. scanf("%d",&H);
69.
70. if(H<2 || H>10)                       /*Each player may have 2 to 10 cards in their hand*/
71. {
72.
73. printf("\n\n TOM joins the game %d, \n ERROR allowed to have only 2 to 10 cards", H);
74. return(0);
75. scanf("%d", &H);
76. }
77.
78. printf("\n TOM enter your cards");     /*another input of TOM*/
79.
80. for(A=0; A<H; A++)
81. {
82. scanf("%d",&TOM[A]);
83.
84. if(TOM[A]<1 || TOM[A]>10)            /* 1 to 10 cards number need to be used */
85. {
86. printf("\n,ERROR cards should be only between 1 to 10 number");
87. return(0);
88.
89. scanf("%d", &TOM[A]);
90. }
91.  }
92.
93.
94.
95.
96.
97.  /*---------now we following the same step for JERRY aka(player2)---------*/
98.
99.
100.
101.
102.  printf("\n JERRY enter the number of cards");     /*input of number of cards for JERRY*/
103.
104.  scanf("%d", &X);
105.
106.  if(X<2 || X>10)                     /*Each player may have 2 to 10 cards in their hand*/
107. {
108.
109. printf("\n\n JERRY joins the game %d, \n ERROR allowed to have only 2 to 10 cards", X);
110. return(0);
111. scanf("%d", &X);
112. }
113.
114. printf("\n JERRY enter your cards");        /*another input of JERRY*/
115.
116. for(A=0; A<X; A++)
117.     {
118. scanf("%d",&JERRY[A]);
119.
120. if(JERRY[A]<1 || JERRY[A]>10)            /* 1 to 10 cards need to be used*/
121. {
122. printf("\n ERROR cards should be only between 1 to 10 number");
123. return(0);
124.
125. scanf("%d", &JERRY[A]);
126. }
127.     }
128.
129.
130.
131.  /*classifying TOM card----- highest to lowest------*/
132.
133.  for(A=0; A<H;  A++)
134.  {
135.
136.  for(B=A+1; B<H;  B++)     {
137.
138.  if(TOM[A] < TOM[B])   {
139.
140.  trash     = TOM[A];             /* suggesting both TOM[A] and TOM[b] to the trash*/
141.  TOM[A] = TOM[B];
142.  TOM[B] = trash;
143.                              }
144.                            }
145.   }
146.
147.
148.  /*classifying JERRY cards-------highest to lowest-----------*/
149.
150.  for(A=0; A<X;  A++)
151.  {
152.
153.  for(B=A+1;  B<X;   B++)    {
154.
155.  if (JERRY[A] < JERRY[B]) {
156.
157.  trash   = JERRY[A];                 /* suggesting both JERRY[A] and JERRY[B] to the trash */
158.  JERRY[A]  = JERRY[B];
159.  JERRY[B]  = trash;
160.                       }
161.                             }
162.   }
163.
164.   printf("\n TOM has %d cards = ",H);     /* releasing out the range of TOM card*/
165.
166.   for(A=0;   A<H;    A++)
167.   {
168.   printf("%d", TOM[A]);
169.    }
170.
171.   printf("\n JERRY has %d cards = ", X);      /* releasing out the range of JERRY cards*/
172.
173.   for (A=0;  A<X;  A++)
174.   {
175.   printf("%d", JERRY[A]);
176.   }
177.
178.
179.
180.
181.
182.   /*working out who got the highest number in between TOM and JERRY*/
183.
184.
185.   if(H > X)
186.  {
187.  Y =  H;
188.                 }
189.
190.  else if(X > H)
191.  {
192.  Y =  X;
193.                 }
194.   else{
195.   Y = H;
196.                 }
197.
198.
199. /*sorting out the winner when one player is out of cards, while the other have more cards*/
200.
201.   for(A= MAXIMUMCARD; A >= H; A--)
202.   { TOM[A]= 0;   }
203.
204.   for(A= MAXIMUMCARD; A >= X; A--)
205.   { JERRY[A] = 0; }
206.
207.
208.  /* finally finding out who the winner is*/
209.
210.  for(A=0;   A<Y;  A++)
211.  {
212.
213.  if(TOM[A] > JERRY[A])
214.  {
215.
216.  winner = 1;               /*TOM is winner 1*/
217.
218.  break;
219.                         }
220.  else if(TOM[A] < JERRY[A]) {
221.
222.  winner = 2;               /*JERRY is winnner 2*/
223.
224.  break;
225.   }
226.  }
227.
228.  if(winner == 1)
229.  {
230.
231.  printf("\n\n *** TOM win the game *** ");
232.                  }
233.  else if(winner == 2)
234.        {
235.  printf("\n\n *** JERRY win the game *** ");
236.  }
237.  else{
238.  printf("\n\n ***   DRAW   ***");
239.       }
240.  }