<mosaic.cnfolio.com>
PROGRAM
1. #include <stdio.h>
2. /*
3. START
4.    WHILE (numberofcards1 is <2) or (numberofcards1 >10) do  //used if statements instead of a while loop because of the compilier
5.       WRITE  Ask How many cards in the hand for player 1;
7.    End WHILE;
8.    WHILE (numofcards2 is < 2), (numofcards2 > 10) or (numofcards1 = numofcards2)
9.       WRITE  Ask How many cards in the hand for player 2;
11.    End WHILE;
12.
13.    FOR  count1 = 0 to numberofcards1, count1++
14.       WRITE Player 1 Enter your card value : x;
16.    END FOR;
17.
18.    FOR count2 = 0 to numberofcards2, count2 ++
19.       WRITE Player 2 Enter your card value : Y;
21.    END FOR:
22.
23.    WRITE “These are player 1’s cards”;
24.    WRITE cardsp1;
25.
26.    WRITE "These are player 2's cards";
27.    WRITE cardsp2;
28.
29.   Player 1 sort ()      //changed sorts to a bubble sort because it had a ideal complexity
30.       position = 0;
31.          while (position < number of cards - 1)
32.                find lowest number after the current position;
33.                lowest number = current position;
34.                position = posistion + 1;
35.          END WHILE;
36.    END sort;
37.
38.    Player 2 sort ()
39.       position = 0;
40.          while (position < number of cards - 1)
41.                find lowest number after the current position;
42.                lowest number = current position;
43.                position = posistion + 1;
44.          END WHILE;
45.    END sort;
46.
47.
48.
49.    FOR ( K = 0; K <= 10; K ++)
50.       IF arrayp1[K] > arrayp2[K]
51.          THEN WRITE Player 1 wins;
52.       IF arrayp2[K] > arrayp1[K]
53.          THEN WRITE Player 2 wins;
54.       IF arrayp1[K] = arrayp2[K]
55.          THEN WRITE Draw;
56.    END FOR;
57.
58.    END;
59.
60. */
61.
62. int main (void)
63. {
64.  int numberofcardsp1 = 0, numberofcardsp2 = 0,  Value1 = 0, Value2 = 0, X =0, count1, count2;
65.    int cardsp1[10] ={0}, cardsp2[10] = {0};
66.    int y = 0, z = 0, temp = 0, temp2 = 0, i = 0, j = 0, b = 0,c= 0;
67.
68.    scanf("%d", &numberofcardsp1);   /*player 1, number of cards input*/
69.
70.          if (numberofcardsp1 <2)     /* if statement for input thats too low*/
71.          {
72.              printf("The number of the card is too low, please try again. \n"); /* Error message*/
73.              return 0;   // Ends nearest function (program)
74.          }
75.
76.          if (numberofcardsp1 >10) // if statement for input thats too high
77.          {
78.             printf("The number of your card is too high, please try again. \n"); //Error message
79.             return 0;   // Ends nearest function (program)
80.          }
81.
82.
83.       for ( count1 = 0; count1 <= numberofcardsp1 - 1; count1 ++) /*loop which increases array position after each input*/
84.       {                                                         /*until it reaches the number of cards*/
85.
86.          scanf("%d", &Value1); // card number input for player 1
87.
88.             if (Value1 < 1 ) /* if statement for input thats too low*/
89.             {
90.                printf("You can't have this card, please enter a card numbered between 2 and 10. \n"); //Error message
91.                 return 0; // Ends nearest function (program)
92.             }
93.
94.            if  (Value1 > 10) // if statement for input thats too high
95.             {
96.                printf("You can't have this card, please enter a card numbered between 2 and 10.\n"); //Error message
97.                 return 0; // Ends nearest function (program)
98.             }
99.
100.          cardsp1[count1] = Value1; // assigning card number to an array position
101.       }
102.
103.    scanf("%d", &numberofcardsp2);
104.
105.           if (numberofcardsp2 <2) /* if statement for input thats too low*/
106.             {
107.                printf("The number of the card is too low, please try again. \n"); //Error message
108.                return 0; // Ends nearest function (program)
109.             }
110.
111.         if (numberofcardsp2 >10) // if statement for input thats too high
112.             {
113.                printf("The number of your card is too high, please try again. \n"); //Error message
114.                 return 0; // Ends nearest function (program)
115.             }
116.
117.    for ( count2 = 0; count2 <= numberofcardsp2 - 1; count2 ++) /*loop which increases array position after each input*/
118.    {                                                            /*until it reaches the number of cards*/
119.
120.          scanf("%d" , &Value2); // card number input for player 2
121.
122.                if (Value2 < 1 ) /* if statement for input thats too low*/
123.                {
124.                   printf("You can't have this card, enter a card numbered between 2 and 10. \n"); //Error message
125.                     return 0; // Ends nearest function (program)
126.                }
127.
128.                if (Value2 > 10) // if statement for input thats too high
129.                {
130.                   printf("You can't have this card, enter a card numbered between 2 and 10.\n"); //Error message
131.                     return 0; // Ends nearest function (program)
132.              }
133.
134.          cardsp2[count2] = Value2; // assigning card number to an array position
135.      }
136.      //bubble sort for player 1
137.      for ( z = 0 ; z < ( numberofcardsp1 - 1 ); z++)  //nested loop, increases until its less than the number of cards -1
138.     {
139.         for (y = 0 ; y < numberofcardsp1 - z - 1; y++) //loop to increase y to the number of cards - the value of z - 1
140.         {
141.             if (cardsp1[y] < cardsp1[y+1])   // compares the current card with the card 1 places above it
142.             {                      // if statement carries out if condition is true
143.            temp = cardsp1[y];    // value in current position is placed into the temp position
144.            cardsp1[y]   = cardsp1[y+1];   // the position is increased by 1
145.            cardsp1[y+1] = temp;        //   the new position is placed into the temp position
146.             }
147.         }
148.     }
149.     // bubble sort for player 2
150.      for ( i = 0 ; i < ( numberofcardsp2 - 1 ); i++)  //nested loop, increases until its less than the number of cards -1
151.     {
152.         for (j = 0 ; j < numberofcardsp2 - i - 1; j++) //loop to increase j to the number of cards - the value of i - 1
153.         {
154.             if (cardsp2[j] < cardsp2[j+1])  // compares the current card with the card 1 places above it
155.             {                    // if statement carries out if condition is true
156.            temp2   = cardsp2[j];   // value in current position is placed into the temp position
157.            cardsp2[j]   = cardsp2[j+1];   // the position is increased by 1
158.            cardsp2[j+1] = temp2; //  the new position is placed into the temp position
159.             }
160.         }
161.     }
162.     /*
163.      for ( z = 0 ; z < numberofcardsp1 ; z++ )
164.      { // loop which increases the value of z until it reaches the number of cards
165.        printf("%d \n", cardsp1[z]);    //prints the value in the array, therefore prints the whole array
166.      }
167.
168.      for ( i = 0 ; i < numberofcardsp2 ; i++ )
169.      {  // loop which increases the value of i until it reaches hte number of cards
170.        printf("%d \n", cardsp2[i]);      //prints the value in the array, therefore prints the whole array
171.      }
172.     */
173.
174.          for ( X = 0; X <= 10 ; X++)      // loop to increase the value of x until it reaches 10
175.          {
176.           if (cardsp1[X] > cardsp2[X])   // compares if player 1's card is bigger than player 2's card
177.           {
178.            printf("Player 1 wins.\n"); // prints player 1 wins
179.            break;                      // ends loop
180.           }
181.
182.           if (cardsp2[X] > cardsp1[X]) // compares if player 2's card is bigger than player 1's card
183.           {
184.            printf("Player 2 wins.\n"); // prints player 2 wins
185.            break;                      // ends loop
186.
187.           }
188.
189.            if (cardsp1[X] == cardsp2[X])   // compares if player 1's card is equal to player 2's card
190.            {
191.              printf("Draw.\n");      // prints if both players draw
192.                 X++;                        // increases x by 1, so the next set of cards are compared
193.            }
194.           }
195.
196.     return 0; // ends program
197. }