Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2014
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.67 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, result = 0;
  9.  
  10.     do
  11.     {
  12.         cout << "Let's play rock-paper-scissors. Enter 1 to choose rock, 2 for paper, and 3 for scissors. Enter 0 to quit." << endl;
  13.         cin >> usr;
  14.    
  15.         switch (usr)
  16.         {
  17.             case 1:
  18.                 cout << "You chose rock." << endl;
  19.                 break;
  20.             case 2:
  21.                 cout << "You chose paper." << endl;
  22.                 break;
  23.             case 3:
  24.                 cout << "You chose scissors." << endl;
  25.                 break;
  26.  
  27.             default:
  28.                 cout << "You done goofed. Input a valid number." << endl;
  29.                
  30.         }
  31.  
  32.     }
  33.  
  34.     while (usr < 0 || usr > 3);
  35.  
  36.     srand(time(NULL));
  37.     cpu = rand() %3 + 1;
  38.  
  39.     if (cpu == 1)
  40.     {
  41.  
  42.     cout << "Computer chose rock." << endl;
  43.  
  44.         if (usr == 1)
  45.         cout << "It's a tie!" << endl;
  46.  
  47.         else if (usr == 2)
  48.         cout << "Computer wins!" << endl;
  49.  
  50.         else
  51.         cout << "You win!" << endl;
  52.     }
  53.  
  54.     else if ( cpu == 2)
  55.     {
  56.  
  57.     cout << "Computer chooses paper." << endl;
  58.  
  59.         if (usr == 1)
  60.         cout << "Computer wins!" << endl;
  61.  
  62.         else if (usr == 2)
  63.         cout << "It's a tie!" << endl;
  64.  
  65.         else
  66.         cout << "You win!" << endl;
  67.     }
  68.  
  69.     else
  70.     {
  71.    
  72.     cout << "Computer chooses scissors." << endl;
  73.         if (usr == 1)
  74.         cout << "You win!" << endl;
  75.  
  76.         else if (usr == 2)
  77.         cout << "Computer wins!" << endl;
  78.  
  79.         else
  80.         cout << "It's a tie!" << endl;
  81.     }
  82.    
  83.     return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement