forked from riyaaa04/cpp20
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path13.cpp
56 lines (53 loc) · 1.48 KB
/
13.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
#include <iostream>
using namespace std;
int main()
{
char playagain;
do
{
//user's choice
cout<<" Choose (R)ock , (S)cissor , (P)aper : " <<endl;
char userchoice;
cin>>userchoice;
//convert user's choice to uppercase
userchoice = toupper(userchoice);
//computer's choice
char computerchoice;
switch (std::rand() % 3)
{
case 0:
computerchoice = 'R';
break;
case 1:
computerchoice = 'S';
break;
case 2:
computerchoice = 'P';
break;
}
//display userchoice
cout<< " You Chose "<< userchoice << endl;
cout<< " Computer Chose "<< computerchoice <<endl;
//Determine the winner
if (userchoice == computerchoice)
{
cout<<" It's a Tie " <<endl;
}
else if ( (userchoice=='R' && computerchoice=='S') ||
(userchoice=='P' && computerchoice=='R') ||
(userchoice=='S' && computerchoice=='P'))
{
cout<<" You Win "<<endl;
}
else
{
cout<<" Computer Wins"<<endl;
}
//Ask if the user wants to play again
cout<<" Do You Want To Play Again ? (Y/N): " <<endl;
cin>>playagain;
}
while (playagain == 'Y' || playagain == 'Y');
cout<<" Thanks for playing . Goodbye!" <<endl;
return 0;
}