-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrockPaperScissor.cpp
More file actions
36 lines (32 loc) · 897 Bytes
/
Copy pathrockPaperScissor.cpp
File metadata and controls
36 lines (32 loc) · 897 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
#include <string>
#include <cstdlib>
#include <array>
bool isWinner(std::string player, std::string ai);
int main()
{
std::string input;
std::array<std::string, 3> possibleAnswers {"rock", "paper", "scissor"};
std::cout << "If you want to exit game, enter \"exit\" \n";
std::string rules = "Enter rock, paper or scissor: ";
do {
std::cout << rules;
std::cin >> input;
std::string answ;
if (input == "exit")
break;
if (isWinner(input, possibleAnswers[rand() % 3]))
std::cout << "Winner\n";
else
std::cout << "Looser\n";
} while(input != "exit");
return 0;
}
bool isWinner(std::string player, std::string ai)
{
if ((player == "scissor" && ai == "paper") ||
(player == "paper" && ai == "rock") ||
(player == "rock" && ai == "scissor"))
return true;
return false;
}