<mosaic.cnfolio.com>
PROGRAM
1. #include <stdio.h>
2. #include <stdlib.h>
3.
4. /* Pseudo code for card game coursework
5.
6. Start
7.    Declare variables (player hand, player etc)
8.
9.    Obtain Player1's hand
10.    while hand1 <1 | >11
11.    scanf
12.    Obtain Player2's Hand
13.    while hand2 <1 | >11
14.    scanf
15.
16.    for loop player1 (;;)
17.    hold card
18.
19.    for loop player2 (;;)
20.    hold card
21.
22.    Sort Player1's hand highest to lowest
23.    Sort Player2's hand highest to lowest
24.
25.    for Player1 and Player2 have cards in hand, condition = true
26.
27.      If Player1's hand > Player2's hand
28.        Print "Player1 Wins!"
29.
30.      If Player2's hand > Player1's hand
31.        Print "Player2 Wins!"
32.
33.      If Player 1's hand = Player2's hand
34.        Print "Draw"
35.
36.    return
37.
38. Finish*/
39. int main(){
40.
41.
42.  int player1[10]//Cards in Player 1 hand
43.  int player2[10]//Cards in Player 1 hand
44.  int hand1=0//Amount of cards in Player 1 hand
45.  int hand2=0//Amount of cards in Player 2 hand
46.  int i,j;   //Used for Loops
47.  int hold;   //Holds current number
48.
49.     while(hand1<1 || hand1>11)
50.     {
51.       printf("Player 1 select ammount of cards and enter cards between 2 and 10 first, ");
52.       scanf(" %d", &hand1);
53.     }
54.
55.       for(i = 0;i<hand1;i++) //player 1 card amount input
56.     {
57.         scanf(" %d", &player1[i]); //player 1 card number input
58.           if(player1[i]<1 || player1[i]>10){
59.             printf("Error. You have entered cards below 1 or above 10!\n"); //returns an error if an incorrect number has been input
60.             }
61.     }
62.
63.     while(hand2<1 || hand2>11)
64.     {
65.       printf("Player 2 enter cards between 2 and 10, ");
66.       scanf(" %d", &hand2); //player 2 card amount input
67.
68.       scanf(" %d", &player2[i]); //player 2 card number input
69.           if(player2[i]<1 || player2[i]>10){
70.             printf("Error. You have entered cards below 1 or above 10!\n"); //returns an error if an incorrect number has been input
71.             }
72.     }
73.     for(i=0;i<hand1-1;i++)
74.     {
75.         for(j=0;j <hand1;j++){  //goes through each element of the array
76.             if(player1[j+1] > player1[j]){
77.                 hold = player1[j];     //stores the current number temporarily
78.                 player1[j] = player1[j+1];
79.                 player1[j+1] = hold;
80.
81.             }
82.         }
83.     }
84.     for(i=0;i<hand2-1;i++)
85.     {
86.         for(j=0;j <hand2;j++){  //goes through each element of the array
87.             if(player2[j+1] > player2[j]){
88.                 hold = player2[j];     //stores the current number temporarily
89.                 player2[j] = player2[j+1];
90.                 player2[j+1] = hold;
91.
92.             }
93.         }
94.     }
95.
96.     for(i=0; i<10;i++)
97.     {
98.         if(hand1 == 0 && hand2 == 0){
99.               printf("Draw!\n");
100.               break;
101.         }
102.         if(hand1 == 0){
103.               printf("Player 2 Wins!\n");
104.               break;
105.         }
106.         if(hand2 == 0){
107.               printf("Player 1 Wins!\n");
108.              break;
109.         }
110.         if(player1[i] == player2[i]){ //if cards are the equal then output comes to a draw
111.                 printf("Draw\n");
112.             break;
113.         }
114.         if(player2[i] > player1[i]){ //if Player 2 hand is greater than Player 1 then player 2 wins
115.             printf("Player 2 Wins!");
116.             break;
117.         }
118.         if(player1[i] > player2[i]){ //if Player 1 hand is greater than Player 2 then player 2 wins
119.             printf("Player 1 Wins!");
120.             break;
121.         }
122.
123.     }
124.   return 0;
125. }