-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rock_paper_scissors.cpp
90 lines (87 loc) · 2.45 KB
/
Rock_paper_scissors.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include<iostream>
#include<stdlib.h>
#include<time.h>
using namespace std;
class gm{
private:
int cchoice,pchoice,pscr,cscr,i = 0;
public:
void game(){
srand(time(NULL));
while(i < 5){
cout<<"\nPress 1 for Rock, 2 for Paper and 3 for Scissors ."<<endl;
cin>>pchoice;
cchoice = rand() % 3 + 1;
if(pchoice == 1){
if(cchoice == 1){
cout<<"\nDraw "<<cchoice;
i++;
}
if(cchoice == 2){
cout<<"\nComputer Wins !!! "<<cchoice;
++cscr;
i++;
}
if(cchoice == 3){
cout<<"\nYou Win !!! "<<cchoice;
++pscr;
i++;
}
}
else if(pchoice == 2){
if(cchoice == 1){
cout<<"\nYou Win !!! "<<cchoice;
++pscr;
i++;
}
if(cchoice == 2){
cout<<"\nDraw !!! "<<cchoice;
i++;
}
if(cchoice == 3){
cout<<"\nComputer Wins !!! "<<cchoice;
++cscr;
i++;
}
}
else if(pchoice == 3){
if(cchoice == 1){
cout<<"\nComputer Wins !!! "<<cchoice;
++cscr;
i++;
}
if(cchoice == 2){
cout<<"\nYou Win !!! "<<cchoice;
++pscr;
i++;
}
if(cchoice == 3){
cout<<"\nDraw !!! "<<cchoice;
i++;
}
}
else{
cout<<"\nINVALID INPUT !!!";
}
}
}
void score(){
if((pscr == cscr)){
cout<<"\nDraw match !!!\n";
}
if(cscr > pscr){
cout<<"\nComputer Wins !!! - score <"<<cscr<<">\n";
}
if(pscr > cscr){
cout<<"\nYou Win !!! - score <"<<pscr<<">\n";
}
}
};
int main(){
cout<<"\tRoCk - pAPeR - ScIsSoRs gAmE"<<endl;
gm g;
g.game();
cout<<"\n";
g.score();
return 0;
}