fork download
  1. #include<stdio.h>
  2. #include<ctype.h>
  3.  
  4. #define TIME_TO_RUN 100 //thimes to random the cards
  5. #define HEART 0//Hearts
  6. #define DIAM 1 //Diamonds
  7. #define CLUB 2 //Clubs
  8. #define SPAD 3 //Spades
  9.  
  10. int isDifference(int val1, int type1, int val2, int type2)
  11. {
  12. return (((val1 == val2) && (type1 == type2)));
  13. }
  14.  
  15. char GetType() //function that returns a random char from 'h'/'d'/'d'/'s' to the card-type
  16. {
  17. int rndType = rand() % 4;
  18. switch (rndType)
  19. {
  20. case HEART:
  21. return 'h';
  22. break;
  23. case DIAM:
  24. return 'd';
  25. break;
  26. case CLUB:
  27. return 'c';
  28. break;
  29. case SPAD:
  30. return 's';
  31. break;
  32. }
  33. }
  34.  
  35. char GetValue()//function that returns a random char from '0'-'9' OR 'J'/'Q'/'K' to the card-number
  36. {
  37. int rndVal = rand() % 13 + 1;
  38.  
  39. switch (rndVal)
  40. {
  41. case 1:
  42. return 'A';
  43. break;
  44. case 2:
  45. return '2';
  46. break;
  47. case 3:
  48. return '3';
  49. break;
  50. case 4:
  51. return '4';
  52. break;
  53. case 5:
  54. return '5';
  55. break;
  56. case 6:
  57. return '6';
  58. break;
  59. case 7:
  60. return '7';
  61. break;
  62. case 8:
  63. return '8';
  64. break;
  65. case 9:
  66. return '9';
  67. break;
  68. case 10:
  69. return '0';
  70. break;
  71. case 11:
  72. return 'J';
  73. break;
  74. case 12:
  75. return 'Q';
  76. break;
  77. case 13:
  78. return 'K';
  79. break;
  80. }
  81. }
  82.  
  83. int IsFlash(int n1, int n2, int n3, int n4, int n5)
  84. {
  85. return ((n1 == n2) && (n3 == n4) && (n1 == n3) && (n1 == n5));
  86. }
  87.  
  88. int main()
  89. {
  90. char cardVal1 = GetValue();
  91. char cardType1 = GetType();
  92. char cardVal2 = GetValue();
  93. char cardType2 = GetType();
  94. char cardVal3 = GetValue();
  95. char cardType3 = GetType();
  96. char cardVal4 = GetValue();
  97. char cardType4 = GetType();
  98. char cardVal5 = GetValue();
  99. char cardType5 = GetType();
  100.  
  101. int countFlash = 0;
  102. int i;
  103.  
  104. for (i = 0; i < TIME_TO_RUN; i++)
  105. {
  106. if (cardVal1 == '0')//if the val is 10 that means that his char-val is '0'. so i print "1" and then the char-val which is "0". and together its "10".
  107. printf("1");
  108. putchar(cardVal1);
  109. putchar(cardType1);
  110. printf("\t");
  111.  
  112. if (cardVal2 == '0')//if the val is 10 that means that his char-val is '0'. so i print "1" and then the char-val which is "0". and together its "10".
  113. printf("1");
  114. putchar(cardVal2);
  115. putchar(cardType2);
  116. printf("\t");
  117.  
  118. if (cardVal3 == '0')//if the val is 10 that means that his char-val is '0'. so i print "1" and then the char-val which is "0". and together its "10".
  119. printf("1");
  120. putchar(cardVal3);
  121. putchar(cardType3);
  122. printf("\t");
  123.  
  124. if (cardVal4 == '0')//if the val is 10 that means that his char-val is '0'. so i print "1" and then the char-val which is "0". and together its "10".
  125. printf("1");
  126. putchar(cardVal4);
  127. putchar(cardType4);
  128. printf("\t");
  129.  
  130. if (cardVal5 == '0')//if the val is 10 that means that his char-val is '0'. so i print "1" and then the char-val which is "0". and together its "10".
  131. printf("1");
  132. putchar(cardVal5);
  133. putchar(cardType5);
  134. printf("\t");
  135.  
  136. printf("\n");
  137.  
  138. if (IsFlash(cardType1, cardType2, cardType3, cardType4, cardType5))
  139. countFlash++;
  140.  
  141. cardVal1 = GetValue();
  142. cardType1 = GetType();
  143. do
  144. {
  145. cardVal2 = GetValue();
  146. cardType2 = GetType();
  147. } while
  148. (isDifference(cardVal1, cardType1, cardVal2, cardType12));//roll another card 2 if card 1 and card 2 are not equal
  149.  
  150. do
  151. {
  152. cardVal3 = GetValue();
  153. cardType3 = GetType();
  154. } while
  155. (isDifference(cardVal1, cardType1, cardVal3, cardType13)//roll another card 3 if card 1 and card 3 are not equal
  156. && isDifference(cardVal2, cardType2, cardVal3, cardType13);
  157.  
  158. do
  159. {
  160. cardVal4 = GetValue();
  161. cardType4 = GetType();
  162. } while
  163. (isDifference(cardVal1, cardType1, cardVal4, cardType14)
  164. && isDifference(cardVal2, cardType2, cardVal4, cardType14)
  165. && isDifference(cardVal3, cardType3, cardVal4, cardType14);
  166.  
  167. do
  168. {
  169. cardVal5 = GetValue();
  170. cardType5 = GetType();
  171. } while
  172. (isDifference(cardVal1, cardType1, cardVal5, cardType15)
  173. && isDifference(cardVal2, cardType2, cardVal5, cardType15)
  174. && isDifference(cardVal3, cardType3, cardVal5, cardType15)
  175. && isDifference(cardVal4, cardType4, cardVal5, cardType15);
  176. }
  177.  
  178. printf("%d flashes happend", countFlash);
  179. return 0;
  180. }
  181.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function ‘GetType’:
prog.c:17:16: warning: implicit declaration of function ‘rand’ [-Wimplicit-function-declaration]
  int rndType = rand() % 4;
                ^~~~
prog.c: In function ‘main’:
prog.c:148:49: error: ‘cardType12’ undeclared (first use in this function)
    (isDifference(cardVal1, cardType1, cardVal2, cardType12));//roll another card 2 if card 1 and card 2 are not equal
                                                 ^~~~~~~~~~
prog.c:148:49: note: each undeclared identifier is reported only once for each function it appears in
prog.c:155:49: error: ‘cardType13’ undeclared (first use in this function)
    (isDifference(cardVal1, cardType1, cardVal3, cardType13)//roll another card 3 if card 1 and card 3 are not equal
                                                 ^~~~~~~~~~
prog.c:156:63: error: expected ‘)’ before ‘;’ token
     && isDifference(cardVal2, cardType2, cardVal3, cardType13);
                                                               ^
prog.c:180:1: error: expected declaration or statement at end of input
 }
 ^
prog.c:180:1: error: expected declaration or statement at end of input
prog.c: In function ‘GetType’:
prog.c:33:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
prog.c: In function ‘GetValue’:
prog.c:81:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
stdout
Standard output is empty