-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRockPaperScissor.cpp
101 lines (88 loc) · 3.17 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include<iostream>
#include<ctime>
using std::cout;
using std::string;
using std::cin;
using std::endl;
char playerChoice();
char computerChoice();
void showchoice(char choice);
void showWinner(char player, char computer);
int main( ){
char player;
char computer;
player = playerChoice();
cout<<"Your Choice - "<<player;
showchoice(player);
computer = computerChoice();
cout<<"\nComputer Choice - "<<computer;
cout<<"\n-------------------\n";
showWinner( player, computer);
return 0;
}
char playerChoice(){
char player;
char choice;
do{
cout<<" -= Rock Papper Scissor =- ";
cout<<" \n ------------------------------ \n ";
cout<<" -= R=- | -= P =- | -= S =- \n";
cin>>player;
}while(player != 'r' && player != 'p' && player != 's');
return player;
}
char computerChoice(){
int num;
srand(time(NULL));
num = rand() %3 +1;
switch(num){
case 1: return 'r';
case 2: return 'p';
case 3: return 's';
}
return 0;
}
void showchoice(char choice){
switch(choice){
case 'r': cout<< " Your Choose -=Rock=- ";
break;
case 'p' : cout <<" You Choose -=Papper=- ";
break;
case 's' : cout<<" You Choose -=Scissor=- ";
break;
}
}
void showWinner(char player, char computer ){
switch(player){
case 'r' : if(computer == 'r'){
cout<<"Its Tie";
}
else if(computer == 's'){
cout<<" your loose";
}
else{
cout<<" You Win ";
}
break;
case 's' : if(computer == 'r'){
cout<<" You Win ";
}
else if(computer == 's'){
cout<<"Its Tie";
}
else{
cout<<" your loose";
}
break;
case 'p' : if(computer == 'r'){
cout<<" your loose";
}
else if(computer == 's'){
cout<<" You Win ";
}
else{
cout<<"Its Tie";
}
break;
}
}