Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <time.h>
  4. int main(void)
  5. {
  6. int choice;
  7. int R=1, P=2, S=3;
  8. int Pscore=0;
  9. int Cscore=0;
  10. int i=0;
  11. srand(time(NULL));
  12.  
  13.  
  14. printf("Play Rock, Paper, Scissors against a computer.\n");
  15.  
  16. printf("Enter 1 for Rock, 2 for Paper, or 3 for Scissors.");
  17. scanf("%d", &choice);
  18. while (i<7)
  19. {
  20. int computer=rand()%3+1;
  21. i++;
  22. switch (choice)
  23.  
  24.  
  25.  
  26. {
  27. case 1:
  28. if (Cscore > 4 || Pscore > 4)
  29. {
  30. break;
  31. }
  32.  
  33. if (computer==1)
  34. {
  35. printf("The computer's choice was:%d\n", computer);
  36. printf("DRAW.\n");
  37. printf("Enter another choice:\n");
  38. scanf("%d", &choice);
  39.  
  40.  
  41. }
  42. else if (computer==2)
  43. {
  44. printf("The computer's choice was:%d\n", computer);
  45. printf("Computer Wins.\n");
  46. printf("Enter another choice:\n");
  47. scanf("%d", &choice);
  48. Cscore= Cscore+1;
  49. }
  50. else if (computer==3)
  51. {
  52. printf("The computer's choice was:%d\n", computer);
  53. printf("You win!\n");
  54. printf("Enter another choice:\n");
  55. scanf("%d", &choice);
  56. Pscore= Pscore+1;
  57. }
  58.  
  59. break;
  60.  
  61. case 2:
  62. if (Cscore > 4 || Pscore > 4)
  63. {
  64. break;
  65. }
  66. if (computer==2)
  67. {
  68. printf("The computer's choice was:%d\n", computer);
  69. printf("DRAW.\n");
  70. printf("Enter another choice:\n");
  71. scanf("%d", &choice);
  72. }
  73. else if (computer==1)
  74. {
  75. printf("The computer's choice was:%d\n", computer);
  76. printf("Computer Wins.\n");
  77. Cscore= Cscore+1;
  78. printf("Enter another choice:\n");
  79. scanf("%d", &choice);
  80. }
  81. else if (computer==3)
  82. {
  83. printf("The computer's choice was:%d\n", computer);
  84. printf("You win!\n");
  85. Pscore= Pscore+1;
  86. printf("Enter another choice:\n");
  87. scanf("%d", &choice);
  88.  
  89. }
  90. break;
  91.  
  92. case 3:
  93. if (Cscore > 4 || Pscore > 4)
  94. {
  95. break;
  96. }
  97. if (computer==3)
  98. {
  99. printf("The computer's choice was:%d\n", computer);
  100. printf("DRAW.\n");
  101. printf("Enter another choice:\n");
  102. scanf("%d", &choice);
  103. }
  104. else if (computer==1)
  105. {
  106. printf("The computer's choice was:%d\n", computer);
  107. printf("Computer Wins.\n");
  108. Cscore= Cscore+1;
  109. printf("Enter another choice:\n");
  110. scanf("%d", &choice);
  111. }
  112. else if (computer==2)
  113. {
  114. printf("The computer's choice was:%d\n", computer);
  115. printf("You win!\n");
  116. Pscore= Pscore+1;
  117. printf("Enter another choice:\n");
  118. scanf("%d", &choice);
  119.  
  120. }
  121.  
  122. default:
  123. printf("Invalid Input\n");
  124. system("clr");
  125.  
  126.  
  127.  
  128. }
  129. }
  130.  
  131.  
  132.  
  133.  
  134. if (Cscore > Pscore || Cscore > 4 )
  135. {
  136.  
  137. printf("Computer has won the matches.\n");
  138. }
  139. else if (Cscore < Pscore || Pscore > 4)
  140. {
  141. printf("You won the matches!\n");
  142. }
  143. else if (Cscore == Pscore && Cscore != 0 && Pscore !=0)
  144. {
  145. printf("It's a DRAW!\n");
  146. }
  147. else
  148. {
  149. printf("Sorry, You have entered the wrong number.");
  150. }
  151. printf("Program will now clear the screen if you press any key.");
  152. getch();
  153. system("cls");
  154. return 0;
  155.  
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement