Guest User

Untitled

a guest
May 24th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class RockPaperScissors{
  6. public:
  7. void getCPUChoice();
  8. void gameOutcome();
  9. void getChoice();
  10. private:
  11. int cpuChoice;
  12. char rps, cpuRps;
  13. };
  14. void RockPaperScissors::gameOutcome(){
  15. if (rps == 'R') cout << "You chose rock" << endl;
  16. else if (rps == 'P') cout << "You chose paper" << endl;
  17. else if (rps == 'S') cout << "You chose scissors" << endl;
  18.  
  19. if (cpuRps == 'R') cout << "CPU chose rock" << endl;
  20. else if (cpuRps == 'P') cout << "CPU chose paper" << endl;
  21. else if (cpuRps == 'S') cout << "CPU chose scissors" << endl;
  22.  
  23. if (rps == 'R' && cpuRps == 'R' || rps == 'P' && cpuRps == 'P' || rps ==
  24. 'S' && cpuRps == 'S') cout << "nIt's a drawn";
  25. else if (rps == 'R' && cpuRps == 'S' || rps == 'S' && cpuRps == 'P' ||
  26. rps == 'P' && cpuRps == 'R') cout << "nYou won!n";
  27. else if (rps == 'S' && cpuRps == 'R' || rps == 'P' && cpuRps == 'S' ||
  28. rps == 'R' && cpuRps == 'P') cout << "/nCPU won!n";
  29. system("pause");
  30. }
  31. void RockPaperScissors::getCPUChoice(){
  32. srand((unsigned)time(0));
  33. cpuChoice = (rand() % 3) + 1;
  34. if (cpuChoice == 1) cpuRps = 'R';
  35. else if (cpuChoice == 2) cpuRps = 'P';
  36. else if (cpuChoice == 3) cpuRps = 'S';
  37. }
  38.  
  39. void RockPaperScissors::getChoice(){
  40. system("CLS");
  41. cout << "Rock, Paper, or Scissors(R,P,S)? ";
  42. cin >> rps;
  43. cout << endl;
  44. }
Add Comment
Please, Sign In to add comment