Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <ctime>
- using namespace std;
- int winner(int, int);
- int randomizer();
- int input();
- int main()
- {
- int compChce = 0;
- int humChce = 0;
- int gameCompleted = 0;
- srand(time(NULL));
- compChce = randomizer();
- humChce = input();
- gameCompleted = winner(compChce, humChce);
- if (gameCompleted == 0)
- {
- compChce = randomizer();
- humChce = input();
- gameCompleted = winner(compChce, humChce);
- }
- system("pause");
- return 0;
- }
- int winner(int compChce, int humChce)
- {
- int game = 0;
- if (compChce == 1)
- {
- if (humChce == 1)
- {
- cout << "It was a tie" << endl;
- }
- else if (humChce == 2)
- {
- cout << "Human wins" << endl;
- game = 1;
- }
- else if (humChce == 3)
- {
- cout << "Computer wins" << endl;
- game = 1;
- }
- }
- else if (compChce == 2)
- {
- if (humChce == 1)
- {
- cout << "Computer wins" << endl;
- game = 1;
- }
- else if (humChce == 2)
- {
- cout << "It was a tie" << endl;
- }
- else if (humChce == 3)
- {
- cout << "Human wins" << endl;
- game = 1;
- }
- }
- else if (compChce == 3)
- {
- if (humChce == 1)
- {
- cout << "Human wins" << endl;
- game = 1;
- }
- else if (humChce == 2)
- {
- cout << "Computer wins" << endl;
- game = 1;
- }
- else if (humChce == 3)
- {
- cout << "It was a tie" << endl;
- }
- }
- return game;
- }
- int randomizer()
- {
- int compChce = 0;
- compChce = rand() % 3 + 1;
- return compChce;
- }
- int input()
- {
- string humInp = "";
- int humChce = 0;
- cout << "1\tRock" << endl;
- cout << "2\tPaper" << endl;
- cout << "3\tScissors" << endl;
- cout << "Please enter the number beside your selection: ";
- cin >> humInp;
- if (humInp != "1" && humInp != "2" && humInp != "3")
- {
- cout << "Please make sure you entered a number between 1 and 3\n";
- }
- else
- {
- humChce = stoi(humInp);
- }
- return humChce;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement