fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int Rock = 0, Paper = 1, Scissors = 2;
  5.  
  6. //MAX FUNCTION
  7. int maximum(float i, float j, float k ) {
  8. int max;
  9. if (i > j && i > k)
  10. max = 0;
  11. else if (j > i && j > k)
  12. max = 1;
  13. else if (k > i && k > j)
  14. max = 2;
  15. else
  16. max = -1;
  17. return max;
  18. }
  19.  
  20. int main(int argc, char* argv[])
  21. {
  22. int player= 3, computer, Vrr=20, Vpr=20, Vsr=20, Vrp=20, Vpp=20, Vsp=20, Vrs=20, Vps=20, Vss=20, max;
  23. float Prr, Prp, Prs, Pps, Ppr, Ppp, Psp, Psr, Pss;
  24. printf("Begin:\n");
  25.  
  26. while (player != -1)
  27. {
  28. printf("Rock (=0), Paper (=1) or Scissors (=2)? To Exit, Enter -1\n");
  29. scanf("%d", &player);
  30.  
  31. //COMPUTING PROBABLITIES
  32. //Subscripts are PLAYER-COMPUTER
  33. if (player == Rock) {
  34. Prr = Vrr / (Vrr + Vrp + Vrs);
  35. Prp = Vrp / (Vrr + Vrp + Vrs);
  36. Prs = Vrs / (Vrr + Vrp + Vrs);
  37. max = maximum(Prr, Prp, Prs);
  38. if (max == -1)
  39. computer = rand() % 3;
  40. else
  41. computer= max;
  42. }
  43. else if (player == Paper) {
  44. Pps = Vps / (Vpr + Vpp + Vps);
  45. Ppr = Vpr / (Vpr + Vpp + Vps);
  46. Ppp = Vpp / (Vpr + Vpp + Vps);
  47. max = maximum(Pps, Ppr, Ppp);
  48. if (max == -1)
  49. computer = rand() % 3;
  50. else
  51. computer= max;
  52. }
  53. else {
  54. Psp = Vsp / (Vsr + Vsp + Vss);
  55. Psr = Vsr / (Vsr + Vsp + Vss);
  56. Pss = Vss / (Vsr + Vsp + Vss);
  57. max = maximum(Psp, Psr, Pss);
  58. if (max == -1)
  59. computer = rand() % 3;
  60. else
  61. computer= max;
  62. }
  63.  
  64. //DISPLAY PLAYER'S MOVE
  65. if (player == 0)
  66. {
  67. printf("Rock\n");
  68. }
  69. else if (player == 1)
  70. {
  71. printf("Paper\n");
  72. }
  73. else if (player == 2)
  74. {
  75. printf("Scissors\n");
  76. }
  77. else
  78. break;
  79.  
  80. //DISPLAY COMPUTER'S MOVE
  81. if (computer == 0)
  82. {
  83. printf("Rock\n");
  84. }
  85. else if (computer == 1)
  86. {
  87. printf("Paper\n");
  88. }
  89. else
  90. {
  91. printf("Scissors\n");
  92. }
  93.  
  94. // DISPLAY RESULTS OF ROUND
  95. if (player == Rock)
  96. {
  97. if (computer == Rock)
  98. {
  99. printf("Draw");
  100. }
  101. else if (computer == Paper)
  102. {
  103. Vrp++;
  104. printf("You Lose!");
  105. }
  106. else
  107. {
  108. Vrs--;
  109. printf("You Win!");
  110. }
  111. }
  112. else if (player == Paper)
  113. {
  114. if (computer == Rock)
  115. {
  116. Vpr--;
  117. printf("You Win");
  118. }
  119. else if (computer == Paper)
  120. {
  121. printf("Draw");
  122. }
  123. else
  124. {
  125. Vpp++;
  126. printf("You Win!");
  127. }
  128. }
  129. else if (player == Scissors)
  130. {
  131. if (computer == Rock)
  132. {
  133. Vsr++;
  134. printf("You Lose!");
  135. }
  136. else if (computer == Paper)
  137. {
  138. Vsp--;
  139. printf("You Win!");
  140. }
  141. else
  142. {
  143. printf("Draw");
  144. }
  145. }
  146. printf("\n");
  147. }
  148. printf("Thank you for playing! :))\n");
  149. return 0;
  150. }
  151.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Begin:
Rock (=0), Paper (=1) or Scissors (=2)? To Exit, Enter -1
Thank you for playing! :))