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