Advertisement
Guest User

Untitled

a guest
May 23rd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <ctime>
  4.  
  5. using namespace std;
  6.  
  7. int winner(int, int);
  8. int randomizer();
  9. int input();
  10.  
  11.  
  12. int main()
  13. {
  14.     int compChce = 0;
  15.     int humChce = 0;
  16.     int gameCompleted = 0;
  17.     srand(time(NULL));
  18.     compChce = randomizer();
  19.     humChce = input();
  20.     gameCompleted = winner(compChce, humChce);
  21.  
  22.     if (gameCompleted == 0)
  23.     {
  24.         compChce = randomizer();
  25.         humChce = input();
  26.         gameCompleted = winner(compChce, humChce);
  27.     }
  28.  
  29.     system("pause");
  30.     return 0;
  31. }
  32.  
  33. int winner(int compChce, int humChce)
  34. {
  35.     int game = 0;
  36.     if (compChce == 1)
  37.     {
  38.         if (humChce == 1)
  39.         {
  40.             cout << "It was a tie" << endl;
  41.         }
  42.         else if (humChce == 2)
  43.         {
  44.             cout << "Human wins" << endl;
  45.             game = 1;
  46.         }
  47.         else if (humChce == 3)
  48.         {
  49.             cout << "Computer wins" << endl;
  50.             game = 1;
  51.         }
  52.     }
  53.     else if (compChce == 2)
  54.     {
  55.         if (humChce == 1)
  56.         {
  57.             cout << "Computer wins" << endl;
  58.             game = 1;
  59.         }
  60.         else if (humChce == 2)
  61.         {
  62.             cout << "It was a tie" << endl;
  63.         }
  64.         else if (humChce == 3)
  65.         {
  66.             cout << "Human wins" << endl;
  67.             game = 1;
  68.         }
  69.     }
  70.     else if (compChce == 3)
  71.     {
  72.         if (humChce == 1)
  73.         {
  74.             cout << "Human wins" << endl;
  75.             game = 1;
  76.         }
  77.         else if (humChce == 2)
  78.         {
  79.             cout << "Computer wins" << endl;
  80.             game = 1;
  81.         }
  82.         else if (humChce == 3)
  83.         {
  84.             cout << "It was a tie" << endl;
  85.         }
  86.     }
  87.     return game;
  88. }
  89.  
  90. int randomizer()
  91. {
  92.     int compChce = 0;
  93.     compChce = rand() % 3 + 1;
  94.     return compChce;
  95. }
  96.  
  97. int input()
  98. {
  99.     string humInp = "";
  100.     int humChce = 0;
  101.    
  102.     cout << "1\tRock" << endl;
  103.     cout << "2\tPaper" << endl;
  104.     cout << "3\tScissors" << endl;
  105.     cout << "Please enter the number beside your selection: ";
  106.    
  107.     cin >> humInp;
  108.    
  109.     if (humInp != "1" && humInp != "2" && humInp != "3")
  110.     {
  111.         cout << "Please make sure you entered a number between 1 and 3\n";
  112.     }
  113.     else
  114.     {
  115.         humChce = stoi(humInp);
  116.     }
  117.     return humChce;
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement