Advertisement
Guest User

Untitled

a guest
Jan 27th, 2013
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.77 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. typedef struct {
  6. char* shortValue;
  7. char shortSuit[1];
  8. char value[20];
  9. char suit[20];
  10. } CARD;
  11.  
  12. CARD cards[5];
  13. int score;
  14. int failed;
  15.  
  16.  
  17. int main(void){
  18.  
  19. /* Putting space between the lines makes it look "Tidy" or "Professional" */
  20.  
  21. printf("Welcome to Poker Game.\n\n");
  22.  
  23. printf("Lets Start.\n\n");
  24.  
  25. printf("Draw Your Cards.\n\n");
  26.  
  27. for(int i = 0; i < 5; i++){
  28. cards[i].shortValue = calloc(1, sizeof(char));
  29. }
  30.  
  31. scanf("%c%c %c%c %c%c %c%c %c%c", cards[0].shortValue, cards[0].shortSuit, cards[1].shortValue, cards[1].shortSuit, cards[2].shortValue, cards[2].shortSuit, cards[3].shortValue, cards[3].shortSuit, cards[4].shortValue, cards[4].shortSuit);
  32.  
  33. /* Use of switch command for long if statement */
  34. /* Use value of 0 as Ten */
  35. /* For each card in input, run check to determine number/letter in word form */
  36.  
  37. for(int i = 0; i < 5; i++){
  38.  
  39. switch(cards[i].shortValue[0])
  40. {
  41.  
  42. case '2':
  43. sprintf(cards[i].value, "Two");
  44. break;
  45.  
  46.  
  47. case '3':
  48. sprintf(cards[i].value, "Three");
  49. break;
  50.  
  51.  
  52. case '4':
  53. sprintf(cards[i].value, "Four");
  54. break;
  55.  
  56.  
  57. case '5':
  58. sprintf(cards[i].value, "Five");
  59. break;
  60.  
  61.  
  62. case '6':
  63. sprintf(cards[i].value, "Six");
  64. break;
  65.  
  66.  
  67. case '7':
  68. sprintf(cards[i].value, "Seven");
  69. break;
  70.  
  71.  
  72. case '8':
  73. sprintf(cards[i].value, "Eight");
  74. break;
  75.  
  76.  
  77. case '9':
  78. sprintf(cards[i].value, "Nine");
  79. break;
  80.  
  81.  
  82. case '0':
  83. sprintf(cards[i].value, "Ten");
  84. break;
  85.  
  86.  
  87. case 'J':
  88. sprintf(cards[i].value, "Jack");
  89. cards[i].value[5] = "11";
  90. score += 1;
  91. break;
  92.  
  93.  
  94. case 'Q':
  95. sprintf(cards[i].value, "Queen");
  96. cards[i].value[5] = "12";
  97. score += 1;
  98. break;
  99.  
  100.  
  101. case 'K':
  102. sprintf(cards[i].value, "King");
  103. cards[i].value[5] = "13";
  104. score += 1;
  105. break;
  106.  
  107.  
  108. case 'A':
  109. sprintf(cards[i].value, "Ace");
  110. cards[i].value[5] = "14";
  111. score += 1;
  112. break;
  113.  
  114.  
  115. default:
  116. printf("Invalid value character for card #%d. \n", i+1);
  117. failed = 1;
  118. break;
  119. }
  120. }
  121.  
  122. /* Run check for all short suits in input */
  123.  
  124. for(int i = 0; i < 5; i++)
  125. {
  126. switch(cards[i].shortSuit[0])
  127. {
  128.  
  129. case 'C':
  130. sprintf(cards[i].suit, "Clubs");
  131. break;
  132.  
  133.  
  134. case 'D':
  135. sprintf(cards[i].suit, "Diamonds");
  136. break;
  137.  
  138.  
  139. case 'H':
  140. sprintf(cards[i].suit, "Hearts");
  141. break;
  142.  
  143.  
  144. case 'S':
  145. sprintf(cards[i].suit, "Spades");
  146. break;
  147.  
  148.  
  149. default:
  150. printf("Invalid suit character for card #%d.\n", i+1);
  151. failed = 1;
  152. break;
  153. }
  154. }
  155.  
  156. if(failed == 1){
  157. printf("Invalid value or suit character. Program exiting.\n");
  158. return 0;
  159. }
  160.  
  161.  
  162. for(int i = 0; i < 5; i++)
  163. printf("%s of %s\n", cards[i].value, cards[i].suit);
  164.  
  165. printf("\n");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement