-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrockpapergame.cpp
More file actions
76 lines (67 loc) · 1.51 KB
/
rockpapergame.cpp
File metadata and controls
76 lines (67 loc) · 1.51 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include<iostream>
#include<cstdlib>
#include<ctime>
char getUserchoice();
char getBotchoice();
int main()
{
char U = getUserchoice();
char B = getBotchoice();
std::cout << "Get user's choice (s,p,c): " << U << "\n";
std::cout << "Get bot's choice (s,p,c): " << B << "\n";
if ((U == B))
{
std::cout << "TIE THE GAME\n";
}
else if (U == 's' && B == 'c')
{
std::cout << "Stone wins\n";
std::cout << "Scissor loses\n";
}
else if (U == 'p' && B == 's')
{
std::cout << "Paper wins\n";
std::cout << "Stone loses\n";
}
else if (U == 'c' && B == 'p')
{
std::cout << "Scissor wins\n";
std::cout << "Paper loses\n";
}
else if (U == 's' && B == 'p')
{
std::cout << "Paper wins\n";
std::cout << "Stone loses\n";
}
else if (U == 'p' && B == 'c')
{
std::cout << "Scissor wins\n";
std::cout << "Paper loses\n";
}
else if (U == 'c' && B == 's')
{
std::cout << "Stone wins\n";
std::cout << "Scissor loses\n";
}
return 0;
}
char getUserchoice()
{
char choice;
std::cout << "Enter your choice (s for stone, p for paper, c for scissor): ";
std::cin >> choice;
return choice;
}
char getBotchoice()
{
std::srand(std::time(0));
int randNum = std::rand() % 3;
char choice;
if (randNum == 0)
choice = 's';
else if (randNum == 1)
choice = 'p';
else
choice = 'c';
return choice;
}