File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments