Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- int main()
- {
- int usr = 1, cpu = 0;
- do
- {
- cout << "Let's play rock-paper-scissors. Enter 1 for rock, 2 for paper, or 3 for scissors." << endl;
- cin >> usr;
- }
- while (usr < 0 || usr > 3);
- if (usr == 1)
- cout << "You chose rock" << endl;
- else if (usr == 2)
- cout << "You chose paper" << endl;
- else if (usr == 3)
- cout << "You chose scissors" << endl;
- srand(time(NULL));
- cpu = rand() %3 + 1;
- if (cpu == 1)
- cout << "Computer chose rock" << endl;
- else if (cpu == 2)
- cout << "Computer chose paper" << endl;
- else
- cout << "Computer chose scissors" << endl;
- if (cpu == usr)
- cout << "It's a tie!" << endl;
- else
- {
- if (usr + cpu == 3)
- {
- cout << "Paper covers rock" << endl;
- if (usr == 2)
- cout << "You win!" << endl;
- else
- cout << "You lose." << endl;
- }
- else if (cpu + usr == 4)
- {
- cout << "Rock crushes scissors" << endl;
- if (usr == 1)
- cout << "You win!" << endl;
- else
- cout << "You lose." << endl;
- }
- else
- {
- cout << "Scissors cut paper" << endl;
- if (usr == 3)
- cout << "You win!" << endl;
- else
- cout << "You lose." << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement