<mosaic.cnfolio.com>
PROGRAM
1. /*pseudo code for coursework
2. START
3.     Player 1 has "x" cards
4.     Player 1 has "x" card, "x" card, "x" card, "x" card...
5.     Player 2 has "x" cards
6.     Player 2 has "x" card, "x" card, "x" card...
7.
8.     IF
9.       player1card1>player2card1
10.        THEN
11.          print "player1 Wins!"
12.     IF
13.       player1_card1<player2_card1
14.        THEN
15.          print "player2 Wins!"
16.     ELSE IF
17.       player1card1==player2card1
18.        THEN
19.          print "round is a Draw"
20.     IF
21.       DRAW
22.         repeat steps line 8 to 15 for card 2, 3,... until a winner has been decided or all cards are used
23. END
24. */
25.
26.     #include <stdio.h>
27.
28.     int main( void )
29.
30.     {
31.     /* There needs to be a number for the cards in the hand followed by the numbers of the cards.
32.        There needs to be enough inputs to satisfy the code, the below code supports up to 4 cards.
33.        Because of this the value 0 needs to be used to fill their hand in if a player does not have 5 cards in their hand*/
34.       int Cards_in_player1_hand ;
35.       int P1Card1, P1Card2, P1Card3, P1Card4 ;
36.       int Cards_in_player2_hand ;
37.       int P2Card1, P2Card2, P2Card3, P2Card4 ;
38.               /* Cards are arranged highest to lowest*/
39.
40.       scanf( "%d" , &Cards_in_player1_hand );
41.       scanf( "%d %d %d %d" , &P1Card1, &P1Card2, &P1Card3, &P1Card4 ) ;
42.       scanf( "%d" , &Cards_in_player2_hand );
43.       scanf( "%d %d %d %d" , &P2Card1, &P2Card2, &P2Card3, &P2Card4 ) ;
44.
45. /* Card1  */
46.       if ( P1Card1>P2Card1 )
47.       {
48.          printf( " Player1 Wins! " ) ;
49.            exit(0) ;
50.       }
51.       if ( P2Card1>P1Card1 )
52.       {
53.          printf( " Player2 Wins! " ) ;       /* if statements that will decide the winner*/
54.             exit(0) ;
55.       }
56.       if ( P1Card1==P2Card1 )
57.       {
58.                 printf( " Draw! " ) ;
59.       }
60.
61. /* Card 2*/
62.       if ( P1Card2>P2Card2 )
63.       {
64.          printf( " Player1 Wins! " ) ;
65.          exit(0) ;
66.       }
67.       if ( P2Card2>P1Card2 )
68.       {
69.          printf( " Player2 Wins! " ) ;
70.          exit(0) ;
71.       }
72.       if ( P1Card2==P2Card2 )
73.       {
74.          printf( " Draw! " ) ;
75.       }
76. /* Card 3*/
77.       if ( P1Card3>P2Card3 )
78.       {
79.          printf( " Player1 Wins! " ) ;
80.          exit(0) ;
81.       }
82.       if ( P2Card3>P1Card3 )
83.       {
84.          printf( " Player2 Wins! " )
85.          exit(0) ;
86.       }
87.        if ( P1Card2==P2Card2 )
88.       {
89.          printf( " Draw! " ) ;
90.       }
91. /* Card 4 */
92.       if ( P1Card4>P2Card4 )
93.       {
94.          printf( " Player1 Wins! " ) ;
95.          exit(0) ;
96.       }
97.       if ( P2Card4>P1Card4 )
98.       {
99.          printf( " Player2 Wins! " ) ;
100.          exit(0) ;
101.       }
102.        if ( P1Card4==P2Card4 )
103.       {
104.          printf( " Draw! " )
105.       }
106.
107.
108.
109.
110.         /*    input test
111.            printf( "%d " ,Cards_in_player1_hand);
112.            printf( "%d " ,P1Card1);
113.            printf( "%d " ,P1Card2);
114.            printf( "%d " ,P1Card3);
115.            printf( "%d " ,P1Card4);
116.
117.            printf( "%d " ,Cards_in_player2_hand);
118.            printf( "%d " ,P2Card1);
119.            printf( "%d " ,P2Card2);
120.            printf( "%d " ,P2Card3);
121.            printf( "%d " ,P2Card4);
122.
123.                                       */
124.   }