Advertisement
Guest User

Untitled

a guest
Feb 17th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. using namespace std;
  5.  
  6. // Function prototype
  7. int getComputerChoice();
  8.  
  9. int main()
  10. {
  11. int win = 0;
  12. int lose = 0;
  13. int tie = 0;
  14. int choice;
  15. int computer = getComputerChoice();
  16. int number;
  17.  
  18. // Constants for the menu choices.
  19. const int Rock = 1,
  20. Paper = 2,
  21. Scissors = 3;
  22.  
  23. //************************************************************
  24. // Definition of function showMenu which displays the menu. *
  25. //************************************************************
  26.  
  27. void showMenu();
  28. {
  29. cout << "\n Lets play Rock, Paper, Scissors!\n\n"
  30. << "1. Rock\n"
  31. << "2. Paper\n"
  32. << "3. Scissors\n"
  33. << "Please enter your choice: ";
  34. cin >> choice;
  35. }
  36.  
  37. if (choice == 1 && computer == 1) {
  38. cout << "Rock meets Rock its a tie!" << endl;
  39. tie++;
  40. }
  41. else if (choice == 1 && computer == 2) {
  42. cout << "Rock is covered by Paper the computer wins!." << endl;
  43. lose++;
  44. }
  45. else if (choice == 1 && computer == 3) {
  46. cout << "Rock crushes Scissors you win!" << endl;
  47. win++;
  48. }
  49. else if (choice == 2 && computer == 1) {
  50. cout << "Paper covers Rock you win!" << endl;
  51. win++;
  52. }
  53. else if (choice == 2 && computer == 2) {
  54. cout << "Paper meets Paper its a tie!" << endl;
  55. tie++;
  56. }
  57. else if (choice == 2 && computer == 3) {
  58. cout << "Paper is cut by Scissors the computer wins!" << endl;
  59. lose++;
  60. }
  61. else if (choice == 3 && computer == 1) {
  62. cout << "Scissors are crushed by Rock computer wins!" << endl;
  63. lose++;
  64. }
  65. else if (choice == 3 && computer == 2) {
  66. cout << "Scissors cuts Paper you win!" << endl;
  67. win++;
  68. }
  69. else if (choice == 3 && computer == 3) {
  70. cout << "Scissors meet Scissors its a tie!" << endl;
  71. tie++;
  72. }
  73.  
  74. // this is what happens if the player doesn't hit 1 2 or 3
  75. else {
  76. cout << "You didn't select 1, 2, or 3" << endl;
  77. }
  78.  
  79. system("pause");
  80. return 0;
  81. }
  82.  
  83. // ********************************************************
  84. // The getComputerChoice function returns the computer's *
  85. // game choice. It returns 1 for rock (via the ROCK *
  86. // constant), or 2 for paper (via the PAPER constant), *
  87. // or 3 for scissors (via the SCISSORS constant). *
  88. // ********************************************************
  89. int getComputerChoice()
  90. {
  91. // Get the system time so we can use it
  92. // to seed the random number generator.
  93. unsigned seed = time(0);
  94.  
  95. // Use the seed value to seed the random
  96. // number generator.
  97. srand(seed);
  98.  
  99. // Generate a random number in the range of 1-3.
  100. int number = 1 + rand() % 3;
  101.  
  102. // Return the random value.
  103. return number;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement