Advertisement
Guest User

roshambo_1

a guest
Oct 23rd, 2014
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.  
  8.     int usr = 1, cpu = 0;
  9.  
  10.     do
  11.     {
  12.         cout << "Let's play rock-paper-scissors. Enter 1 for rock, 2 for paper, or 3 for scissors." << endl;
  13.    
  14.         cin >> usr;
  15.     }
  16.  
  17.     while (usr < 0 || usr > 3);
  18.  
  19.     if (usr == 1)
  20.         cout << "You chose rock" << endl;
  21.  
  22.     else if (usr == 2)
  23.         cout << "You chose paper" << endl;
  24.  
  25.     else if (usr == 3)
  26.         cout << "You chose scissors" << endl;
  27.  
  28.  
  29.     srand(time(NULL));
  30.     cpu = rand() %3 + 1;
  31.  
  32.     if (cpu == 1)
  33.         cout << "Computer chose rock" << endl;
  34.  
  35.     else if (cpu == 2)
  36.         cout << "Computer chose paper" << endl;
  37.  
  38.     else
  39.         cout << "Computer chose scissors" << endl;
  40.  
  41.  
  42.     if (cpu == usr)
  43.         cout << "It's a tie!" << endl;
  44.  
  45.     else
  46.     {
  47.         if (usr + cpu == 3)
  48.         {
  49.             cout << "Paper covers rock" << endl;
  50.  
  51.             if (usr == 2)
  52.                 cout << "You win!" << endl;
  53.  
  54.             else
  55.                 cout << "You lose." << endl;
  56.         }
  57.  
  58.         else if (cpu + usr == 4)
  59.         {
  60.             cout << "Rock crushes scissors" << endl;
  61.  
  62.             if (usr == 1)
  63.                 cout << "You win!" << endl;
  64.  
  65.             else
  66.                 cout << "You lose." << endl;
  67.         }
  68.  
  69.         else
  70.         {
  71.              cout << "Scissors cut paper" << endl;
  72.  
  73.              if (usr == 3)
  74.                  cout << "You win!" << endl;
  75.  
  76.              else
  77.                  cout << "You lose." << endl;
  78.         }
  79.     }
  80.  
  81.     return 0;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement