Skip to content

Commit 3e547eb

Browse files
authored
Create rock-paper-scissors game.cpp
1 parent 32bec9c commit 3e547eb

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

rock- paper-scissors game.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#include<iostream>
2+
#include<cstdlib>
3+
4+
5+
using namespace std;
6+
7+
int main(){
8+
int x, probability ;
9+
cout << "rock, paper, scissors game \n"<< " pick one of them : \n";
10+
string pick , computer ;
11+
string list[3]={"rock" ,"paper" ,"scissors" };
12+
cin >> pick;
13+
x= time(0) , probability;
14+
srand(x);
15+
probability= 1 + rand()% 3;
16+
if(probability == 1){
17+
cout << "";
18+
computer = list[0];
19+
20+
}
21+
else if(probability == 1){
22+
cout << "";
23+
computer = list[1] ;
24+
25+
}
26+
else{
27+
cout << "";
28+
computer = list[2] ;
29+
30+
}
31+
32+
33+
cout << computer << endl;
34+
if (computer == pick ){
35+
cout << "draw"<<endl ;
36+
}
37+
else if (computer != pick){
38+
if ((computer=="rock" && pick =="paper")||(computer=="scissors" && pick=="rock")||(computer=="paper" && pick =="scissors")){
39+
cout << "you won ";}
40+
else if((pick == "rock" && computer == "paper") || (pick == "scissors" && computer == "rock") || (pick == "paper" && computer == "scissors")
41+
){
42+
cout << "you lose" << endl;}}
43+
44+
else{
45+
cout<< "";
46+
}
47+
return 0;
48+
49+
}

0 commit comments

Comments
 (0)