Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib> //srand, rand
- #include <ctime>
- using namespace std;
- void show_winner(string p1, string p2)
- {
- if (p1 == "Paper" && p2 == "Rock"
- || p1 == "Rock" && p2 == "Scissors"
- || p1 == "Scissors" && p2 == "Paper")
- {
- cout << " :-) Human wins!" << endl;
- }
- else if (p1 == p2)
- {
- cout << " :-| This is a tie" << endl;
- }
- else
- {
- cout << " :-( Computer Wins!" << endl;
- }
- }
- string get_computer_choice()
- {
- int selection = rand() % 3;
- if (selection == 0)
- {
- return "paper";
- }
- else if (selection == 1)
- {
- return "rock";
- }
- else
- {
- return "scissors";
- }
- }
- string get_user_choice()
- {
- string input;
- cout << "Enter paper, rock, or scissors" << endl;
- cin >> input;
- return input;
- }
- int main()
- {
- srand(time(NULL));
- cout << "---Paper --- Rock --- Scissors---" << endl;
- string p1 = get_user_choice();
- string p2 = get_computer_choice();
- show_winner(p1,p2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement