Advertisement
Guest User

Untitled

a guest
Jun 24th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. // Week 2 Assignment.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <cstdlib>
  6. #include <iostream>
  7. #include <string>
  8.  
  9. using namespace std;
  10.  
  11.  
  12. int main()
  13. {
  14. enum choice { Rock, Paper, Scissors };
  15. int user;
  16. choice select;
  17. choice cpu_select;
  18. int computer = rand();
  19. computer = rand() % 3;
  20. int num_ties = 0;
  21. bool tie = false;
  22. int player_wins = 0;
  23. int cpu_wins = 0;
  24. int num_ties = 0;
  25. int num_games = 0;
  26. string play;
  27. bool play_again;
  28.  
  29.  
  30.  
  31. cout << "Please enter 'R' for Rock, 'P for Paper, or 'S for Scissors. ('r', 'p', or 's')" << endl;
  32. cin >> user;
  33. cout << endl;
  34.  
  35. if (user == 'R') {
  36. select = Rock;
  37. } if (user == 'P') {
  38. select = Paper;
  39. } if (user == 'S') {
  40. select = Scissors; }
  41.  
  42. { while (cpu_select == select) {
  43. cout << "It's a tie, try again";
  44. cin >> user;
  45. }
  46.  
  47. choice cpu_select;
  48. if (computer == 0) {
  49. cpu_select = Rock;
  50. }
  51. else if (computer == 1) {
  52. cpu_select = Paper;
  53. }
  54. else if (computer == 2) {
  55. cpu_select = Scissors;
  56. }
  57. cout << endl << endl << "Your selection is " << select << endl;
  58. cout << endl << "The computer selects " << cpu_select << endl;
  59.  
  60. bool you_win = false;
  61.  
  62. if ((select == Rock && cpu_select == Scissors) || (select == Paper && cpu_select == Rock) || (select == Scissors && cpu_select == Paper)) {
  63. cout << endl << "You win" << endl;
  64. player_wins++;
  65. }
  66. else if ((cpu_select == Rock && select == Scissors) || (cpu_select == Paper && select == Rock) || (cpu_select == Scissors && select == Paper)) {
  67. cout << endl << "The computer wins" << endl;
  68. cpu_wins++;
  69. }
  70. else if (cpu_select == select) {
  71. num_ties++;
  72. }
  73. cout << endl << "You have won" << player_wins << " games and lost" << cpu_wins << "games" << endl;
  74.  
  75. cout << endl << endl << "Would you like to play again?";
  76. cin >> play;
  77.  
  78. if (play == 'N' || play == 'n') {
  79. play_again == false;
  80. }
  81. else if (play == 'Y' || play == 'y') {
  82. num_games++;
  83. }}
  84.  
  85.  
  86. return 0;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement