<mosaic.cnfolio.com>
PROGRAM
1. /*
2. START
3.     SCAN for Inputs
4.
5.     IF (Player 1 has too many cards)
6.         DISPLAY (Player 1 has too many cards)
7.     END IF
8.
9.     IF (Player 1 has too few cards)
10.         DISPLAY (Player 1 has too few cards)
11.     END IF
12.
13.     IF (Player 2 has too many cards)
14.         DISPLAY (Player 1 has too many cards)
15.     END IF
16.
17.     IF (Player 2 has too few cards)
18.         DISPLAY (Player 1 has too few cards)
19.     END IF
20.
21.     IF (Player 1 has cards too high)
22.         DISPLAY (Player 1 has too many cards)
23.     END IF
24.
25.     IF (Player 1 has cards too low)
26.         DISPLAY (Player 1 has too few cards)
27.     END IF
28.
29.     IF (Player 2 has cards too high)
30.         DISPLAY (Player 1 has too many cards)
31.     END IF
32.
33.     IF (Player 2 cards too low)
34.         DISPLAY (Player 1 has too few cards)
35.     END IF
36.
37.     BUBBLESORT Player 1 cards from Highest to Lowest
38.
39.    for x less than or equal to 10, increment x
40.    IF (Player1cards x is less than than player1cards x+1)
41.     x=temporary
42.     x+1=x
43.     temporary=x+1
44.    END IF
45.
46.    END FOR
47.
48.     BUBBLESORT Player 2 cards from Highest to Lowest
49.
50.    for x less than or equal to 10, increment x
51.    IF (Player2cards x is less than than player2cards x+1)
52.     x=temporary
53.     x+1=x
54.     temporary=x+1
55.    END IF
56.
57.    END FOR
58.     IF (Player1 Card1 > Player2 Card1)
59.         DISPLAY (Player1 Wins)
60.         GOTO END
61.     END IF
62.
63.     IF (Player1 Card1 < Player2 Card1)
64.         DISPLAY (Player2 Wins)
65.         GOTO END
66.     END IF
67.
68.     IF (Player1 Card1 = Player2 Card1)
69.         next = 1
70.     END IF
71.
72.     IF (next = 1)
73.         next = 0
74.         IF (Player1 Card2 > Player2 Card2)
75.             DISPLAY (Player1 Wins)
76.             GOTO END
77.         END IF
78.
79.         IF (Player1 Card2 < Player2 Card2)
80.             DISPLAY (Player2 Wins)
81.             GOTO END
82.         END IF
83.
84.         IF (Player1 Card2 = Player2 Card2)
85.             next = 1
86.         END IF
87.
88.             (CARRY ON THROUGH CARD 10)
89.
90.     END IF */
91. #include <stdio.h>
92.
93. void
94. main (void)
95. {
96.   int p1num, p2num, x, swap, j, q, z,A, temp;
97.   int player1cards[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
98.   int player2cards[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
99.   int cardmaxnum, cardminnum, cardvalmin, cardvalmax;
100.   int outside, inside, lowest, tmpSwapValue;
101.   int win, cont, error;
102.   win = 0;
103.   error = 0;
104.   cont = 1;
105.   cardmaxnum = 10;
106.   cardminnum = 2;
107.   cardvalmax = 10;
108.   cardvalmin = 1;
109.
110. /* This is where i am scanning the inputs for the quantity of cards the players have
111. I am using if statements to produce error messages*/
112. scanf ("%d", &p1num);
113.   if (p1num < cardminnum)
114.
115.     {
116.       printf ("*P1 TOO FEW CARDS, PLEASE TRY AGAIN\n");
117.       error = 1;
118.     }
119.   if (p1num > cardmaxnum)
120.     {
121.       printf ("*P1 TOO MANY CARDS, PLEASE TRY AGAIN\n");
122.        error = 1;
123.     }
124.
125.   for (x = 0; x < p1num; x++)
126.     {
127.       scanf ("%d", &player1cards[x]);
128.
129.
130.     }
131.   scanf ("%d", &p2num);
132.   if (p2num < cardminnum)
133.
134.     {
135.       printf ("*P2 TOO FEW CARDS, PLEASE TRY AGAIN\n");
136.        error = 1;
137.     }
138.
139.   if (p2num > cardmaxnum)
140.     {
141.       printf ("*P2 TOO MANY CARDS, PLEASE TRY AGAIN\n");
142.        error = 1;
143.     }
144.
145.   for (q = 0; q < p2num; q++)
146.     {
147.       scanf ("%d", &player2cards[q]);
148.     }
149.   {
150.
151.  /*this is my first sort it uses a temporary location to swap the variables to put thm into order
152. i used this sort as i knew how to put it into descending order effectively */
153.     for (z = p1num - 2; z >= 0; z--)
154.       {
155.    for (j = 0; j <= z; j++)
156.      {
157.        if (player1cards[j] < player1cards[j + 1])
158.          {
159.       temp = player1cards[j];
160.       player1cards[j] = player1cards[j + 1];
161.       player1cards[j + 1] = temp;
162.          }
163.      }
164.       }
165.  /* this is where i produced the error messages for the values of players i originally used loops however when ever i tried implementing it the loops interfered with the rest of the code
166. i could not get it working so i resulted to the less efficient method of going through each memory location manually*/
167.      A=0;
168.        if (player1cards[A] < 0)
169.       {
170.          printf("Player 1 has values too small\n");
171.           error = 1;
172.       }
173.       if (player1cards[A] > 10)
174.       {
175.          printf("Player 1 has values too large\n");
176.           error = 1;
177.       }
178.       if (player2cards[A] < 0)
179.       {
180.          printf("Player 2 has values too small\n");
181.           error = 1;
182.       }
183.       if (player2cards[A] > 10)
184.       {
185.          printf("Player 2 has values too large\n");
186.           error = 1;
187.       A = 1;
188.       }
189.       if (player1cards[A] < 0)
190.       {
191.          printf("Player 1 has values too small\n");
192.           error = 1;
193.       }
194.       if (player1cards[A] > 10)
195.       {
196.          printf("Player 1 has values too large\n");
197.           error = 1;
198.       }
199.       if (player2cards[A] < 0)
200.       {
201.          printf("Player 2 has values too small\n");
202.           error = 1;
203.       }
204.       if (player2cards[A] > 10)
205.       {
206.          printf("Player 2 has values too large\n");
207.           error = 1;
208.       }
209.        A =2;
210.        if (player1cards[A] < 0)
211.       {
212.          printf("Player 1 has values too small\n");
213.           error = 1;
214.       }
215.       if (player1cards[A] > 10)
216.       {
217.          printf("Player 1 has values too large\n");
218.           error = 1;
219.       }
220.       if (player2cards[A] < 0)
221.       {
222.          printf("Player 2 has values too small\n");
223.           error = 1;
224.       }
225.       if (player2cards[A] > 10)
226.       {
227.          printf("Player 2 has values too large\n");
228.          error = 1;
229.       }
230.       A = 3;
231.       if (player1cards[A] < 0)
232.       {
233.          printf("Player 1 has values too small\n");
234.           error = 1;
235.       }
236.       if (player1cards[A] > 10)
237.       {
238.          printf("Player 1 has values too large\n");
239.           error = 1;
240.       }
241.       if (player2cards[A] < 0)
242.       {
243.          printf("Player 2 has values too small\n");
244.          error = 1;
245.       }
246.       if (player2cards[A] > 10)
247.       {
248.          printf("Player 2 has values too large\n");
249.           error = 1;
250.       }
251.       A =4;
252.       if (player1cards[A] < 0)
253.       {
254.          printf("Player 1 has values too small\n");
255.           error = 1;
256.       }
257.       if (player1cards[A] > 10)
258.       {
259.          printf("Player 1 has values too large\n");
260.           error = 1;
261.       }
262.       if (player2cards[A] < 0)
263.       {
264.          printf("Player 2 has values too small\n");
265.           error = 1;
266.       }
267.       if (player2cards[A] > 10)
268.       {
269.          printf("Player 2 has values too large\n");
270.           error = 1;
271.       }
272.        A = 5;
273.        if (player1cards[A] < 0)
274.       {
275.          printf("Player 1 has values too small\n");
276.           error = 1;
277.       }
278.       if (player1cards[A] > 10)
279.       {
280.          printf("Player 1 has values too large\n");
281.           error = 1;
282.       }
283.       if (player2cards[A] < 0)
284.       {
285.          printf("Player 2 has values too small\n");
286.           error = 1;
287.       }
288.       if (player2cards[A] > 10)
289.       {
290.          printf("Player 2 has values too large\n");
291.           error = 1;
292.       }
293.        A = 6;
294.        if (player1cards[A] < 0)
295.       {
296.          printf("Player 1 has values too small\n");
297.           error = 1;
298.       }
299.       if (player1cards[A] > 10)
300.       {
301.          printf("Player 1 has values too large\n");
302.          error = 1;
303.       }
304.       if (player2cards[A] < 0)
305.       {
306.          printf("Player 2 has values too small\n");
307.           error = 1;
308.       }
309.       if (player2cards[A] > 10)
310.       {
311.          printf("Player 2 has values too large\n");
312.           error = 1;
313.       }
314.       A = 7;
315.       if (player1cards[A] < 0)
316.       {
317.          printf("Player 1 has values too small\n");
318.           error = 1;
319.       }
320.       if (player1cards[A] > 10)
321.       {
322.          printf("Player 1 has values too large\n");
323.           error = 1;
324.       }
325.       if (player2cards[A] < 0)
326.       {
327.          printf("Player 2 has values too small\n");
328.           error = 1;
329.       }
330.       if (player2cards[A] > 10)
331.       {
332.          printf("Player 2 has values too large\n");
333.           error = 1;
334.       }
335.        A = 8;
336.        if (player1cards[A] < 0)
337.       {
338.          printf("Player 1 has values too small\n");
339.           error = 1;
340.       }
341.       if (player1cards[A] > 10)
342.       {
343.          printf("Player 1 has values too large\n");
344.           error = 1;
345.       }
346.       if (player2cards[A] < 0)
347.       {
348.          printf("Player 2 has values too small\n");
349.           error = 1;
350.       }
351.       if (player2cards[A] > 10)
352.       {
353.          printf("Player 2 has values too large\n");
354.           error = 1;
355.       }
356.        A = 9;
357.        if (player1cards[A] < 0)
358.       {
359.          printf("Player 1 has values too small\n");
360.           error = 1;
361.       }
362.       if (player1cards[A] > 10)
363.       {
364.          printf("Player 1 has values too large\n");
365.           error = 1;
366.       }
367.       if (player2cards[A] < 0)
368.       {
369.          printf("Player 2 has values too small\n");
370.           error = 1;
371.       }
372.       if (player2cards[A] > 10)
373.       {
374.          printf("Player 2 has values too large\n");
375.           error = 1;
376.       }
377.       /*this is my second sort*/
378.
379.     {
380.       for (z = p2num - 2; z >= 0; z--)
381.    {
382.      for (j = 0; j <= z; j++)
383.        {
384.          if (player2cards[j] < player2cards[j + 1])
385.       {
386.         temp = player2cards[j];
387.         player2cards[j] = player2cards[j + 1];
388.         player2cards[j + 1] = temp;
389.       }
390.        }
391.    }
392.    /*here i have used if statements to cycle and compare the two arrays and to produce an output
393.    then terminate the programme when there is a winner
394.    when there is a loser it cycles the whole way through both arrays and terminates it after printing that there was a draw*/
395.    A = 0;
396.
397.
398.       while (cont != 0)
399.       {
400.
401.       if (player1cards[A] > player2cards[A])
402.       {
403.       win = 1;
404.       cont = 0;
405.       }
406.       if (player1cards[A] < player2cards[A])
407.       {
408.       win = 2;
409.       cont = 0;
410.       }
411.       if (player1cards[A] == player2cards[A])
412.       {
413.       cont++;
414.       A++;
415.       if (cont == 10)
416.          {
417.          win = 3;
418.          cont = 0;
419.           }
420.       }
421.
422.     }
423.
424.
425.    if (error != 1)
426.    {
427.     if (win == 1)
428.     {
429.       printf("Player 1 wins. \n");
430.     }
431.
432.     if (win == 2)
433.     {
434.       printf("Player 2 wins. \n");
435.     }
436.
437.     if (win == 3)
438.     {
439.       printf("Draw. \n");
440.     }}
441.     }
442. }
443. }