Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Card dealing program */
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- void shuffle(int [][13]);
- void deal(int [][13], char *[], char *[], int[], int[]);
- void pair(int [], int []);
- void main()
- {
- char *suit[4]={"Hearts", "Diamonds", "Clubs", "Spades"};
- char *face[13]={"Ace", "Deuce", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"};
- int myFace[5];
- int mySuit[5];
- int deck[4][13] = {0};
- srand(time(0));
- shuffle(deck);
- deal(deck, face, suit, myFace, mySuit);
- pair(myFace, mySuit);
- }
- void shuffle(int workdeck[][13])
- {
- int card, row, column;
- for(card = 1; card <= 52; card++)
- {
- row = rand() % 4;
- column = rand() % 13;
- while(workdeck[row][column] != 0)
- {
- row = rand() % 4;
- column = rand() % 13;
- }
- workdeck[row][column] = card;
- }
- }
- void deal(int workdeck2[][13], char *workface[], char *worksuit[], int myFace[], int mySuit[])
- {
- int card, row, column, i;
- for (card = 1; card <= 5; card++)
- for (row = 0; row <= 3; row++)
- for (column = 0; column <= 12; column++)
- if (workdeck2[row][column] == card)
- {
- printf("%5s of %-8s",
- workface[column], worksuit[row]);
- if (card % 2 == 0)
- puts("");
- else
- printf("\t");
- myFace[card - 1] = row;
- mySuit[card - 1] = column;
- break;
- }
- }
- void pair(int myFace[], int mySuit[])
- {
- int i, j, pairQ;
- for(i = 0; i < 5; i++){
- for(j = i + 1; j < 4; j++){
- if(myFace[i] == myFace[j]){
- pairQ++;
- }
- }
- }
- switch(pairQ){
- case 0:
- printf("Nothing.");
- break;
- case 2:
- printf("Pair.");
- break;
- case 4:
- printf("2 Pair");
- break;
- case 6:
- printf("3 of a kind");
- break;
- case 7:
- printf("4 of a kind.");
- break;
- }
- }
Add Comment
Please, Sign In to add comment