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, result = 0;
- do
- {
- cout << "Let's play rock-paper-scissors. Enter 1 to choose rock, 2 for paper, and 3 for scissors. Enter 0 to quit." << endl;
- cin >> usr;
- switch (usr)
- {
- case 1:
- cout << "You chose rock." << endl;
- break;
- case 2:
- cout << "You chose paper." << endl;
- break;
- case 3:
- cout << "You chose scissors." << endl;
- break;
- default:
- cout << "You done goofed. Input a valid number." << endl;
- }
- }
- while (usr < 0 || usr > 3);
- srand(time(NULL));
- cpu = rand() %3 + 1;
- if (cpu == 1)
- {
- cout << "Computer chose rock." << endl;
- if (usr == 1)
- cout << "It's a tie!" << endl;
- else if (usr == 2)
- cout << "Computer wins!" << endl;
- else
- cout << "You win!" << endl;
- }
- else if ( cpu == 2)
- {
- cout << "Computer chooses paper." << endl;
- if (usr == 1)
- cout << "Computer wins!" << endl;
- else if (usr == 2)
- cout << "It's a tie!" << endl;
- else
- cout << "You win!" << endl;
- }
- else
- {
- cout << "Computer chooses scissors." << endl;
- if (usr == 1)
- cout << "You win!" << endl;
- else if (usr == 2)
- cout << "Computer wins!" << endl;
- else
- cout << "It's a tie!" << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement