-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrock_paper_scissor.cpp
60 lines (46 loc) · 1.44 KB
/
rock_paper_scissor.cpp
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
#include<iostream>
#include<cstdlib>
#include<ctime>
#include<string>
int main(){
srand(time(NULL));
system("CLS");
std::string option[3] = {"r","p","s"};
int machine_choice = 1+(rand()%3);
int i = 0;
std::string user, machine;
machine = option[machine_choice];
while(i != 10){
std::cout<<"Enter the option: ";
std::cin>>user;
if(user=="r" || user=="s" || user=="p"){
std::cout<<"machine: "<<machine<<std::endl;
std::cout<<"user: "<<user<<std::endl;
if(user=="r" && option[machine_choice]=="s"){
std::cout<<"user is winner"<<std::endl;
i++;
}
else if(user=="p" && option[machine_choice]=="r"){
std::cout<<"user is winner"<<std::endl;
i++;
}
else if(user=="s" && option[machine_choice]=="p"){
std::cout<<"user is winner"<<std::endl;
i++;
}
else if(user==option[machine_choice]){
std::cout<<"draw match"<<std::endl;
i++;
}
else{
std::cout<<"machine is winner"<<std::endl;
i++;
}
std::cout<<std::endl;
}
else{
std::cout<<"Invalid Input"<<std::endl;
}
}
return 0;
}