-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRockPaperScissor.cpp
79 lines (56 loc) · 1.61 KB
/
RockPaperScissor.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
#include<iostream>
#include<ctime>
#include<cstdlib>
int check(int &, int &);
int input(int &);
void layout();
using namespace std;
int main(){
layout();
int userchoice,com,catcher=2;
string arr[3]={"Rock","Paper","Scissor"};
srand(time(0));
com=rand() % 3;
input(userchoice);
cout<<"\n You chose "<<arr[userchoice-1]<<" & the computer chose "<<arr[com-1]<<endl;
catcher=check(userchoice, com);
switch(catcher){
case 1:
cout<<"\n Congratulations, you won \n";
system("pause");
break;
case 0:
cout<<"\n The computer won \n";
system("pause");
break;
case 2:
cout<<"\n Its a draw \n";
system("pause");
break;
}
}
void layout(){
cout<<" **************************************************************"<<endl;
cout<<" * Rock, Paper, Scissor *"<<endl;
cout<<" **************************************************************"<<endl;
cout<<"\n You are playing against computer, 1 is for Rock, 2 is for Paper & 3 is for Scissor"<<endl;
}
int input(int &userchoice){
cout<<"\n What do you choose!"<<endl;
cin>>userchoice;
}
int check(int &userchoice, int &com){
if(userchoice==1 && com==3)
return 1;
else if(userchoice==2 && com==1)
return 1;
else if(userchoice==3 && com==2)
return 1;
if(userchoice==3 && com==1)
return 0;
else if(userchoice==1 && com==2)
return 0;
else if(userchoice==2 && com==3)
return 0;
else return 2;
}