Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class RockPaperScissors{
- public:
- void getCPUChoice();
- void gameOutcome();
- void getChoice();
- private:
- int cpuChoice;
- char rps, cpuRps;
- };
- void RockPaperScissors::gameOutcome(){
- if (rps == 'R') cout << "You chose rock" << endl;
- else if (rps == 'P') cout << "You chose paper" << endl;
- else if (rps == 'S') cout << "You chose scissors" << endl;
- if (cpuRps == 'R') cout << "CPU chose rock" << endl;
- else if (cpuRps == 'P') cout << "CPU chose paper" << endl;
- else if (cpuRps == 'S') cout << "CPU chose scissors" << endl;
- if (rps == 'R' && cpuRps == 'R' || rps == 'P' && cpuRps == 'P' || rps ==
- 'S' && cpuRps == 'S') cout << "nIt's a drawn";
- else if (rps == 'R' && cpuRps == 'S' || rps == 'S' && cpuRps == 'P' ||
- rps == 'P' && cpuRps == 'R') cout << "nYou won!n";
- else if (rps == 'S' && cpuRps == 'R' || rps == 'P' && cpuRps == 'S' ||
- rps == 'R' && cpuRps == 'P') cout << "/nCPU won!n";
- system("pause");
- }
- void RockPaperScissors::getCPUChoice(){
- srand((unsigned)time(0));
- cpuChoice = (rand() % 3) + 1;
- if (cpuChoice == 1) cpuRps = 'R';
- else if (cpuChoice == 2) cpuRps = 'P';
- else if (cpuChoice == 3) cpuRps = 'S';
- }
- void RockPaperScissors::getChoice(){
- system("CLS");
- cout << "Rock, Paper, or Scissors(R,P,S)? ";
- cin >> rps;
- cout << endl;
- }
Add Comment
Please, Sign In to add comment