-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
89 lines (82 loc) · 2.18 KB
/
main.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
#include <iostream>
#include<ctime>
using namespace std;
const char ROCK = 'R';
const char PAPER = 'P';
const char SCISSOR = 'S';
char getcomputeroption(){
srand(time(0));
int num = rand() % 3 + 1;
if(num == 1){
return 'R';
}
if(num == 2){
return 'P';
}
if(num == 3){
return 'S';
}
}
char useroption(){
char c;
cout<<"Rock, Paper and Scissor Game!!"<<endl;
cout<<"Choose one of the following options: "<<endl;
cout<<"------------------------------------"<<endl;
cout<<"(R) for Rock, (P) for Paper and (S) for scissors(Plz type in capitals only):"<<endl;
cin>>c;
while(c!='R'&& c!='P'&& c!='S'){
cout<<"Please enter one of the options in the following: ";
cout<<"(R) for rocks"<<endl<<"(P for paper)"<<endl<<"(S) for scissors";
cin >> c;
}
return c;
};
void choosewinner( char uchoice, char cchoice){
if(uchoice == ROCK && cchoice == PAPER){
cout<<"Computer wins!!"<<endl;
}
else if(uchoice == PAPER && cchoice == SCISSOR){
cout<<"Computer wins!!"<<endl;
}
else if(uchoice == SCISSOR && cchoice == ROCK){
cout<<"Computer wins"<<endl;
}
else if(uchoice == ROCK && cchoice == SCISSOR){
cout<<"User wins!!"<<endl;
}
else if(uchoice == PAPER && cchoice == ROCK){
cout<<"User wins!!"<<endl;
}
else if(uchoice == SCISSOR && cchoice == PAPER){
cout<<"User wins!!"<<endl;
}
else{
cout<<"Tie, play again"<<endl;
}
}
void showoptions(char option){
if(option == 'R'){
cout<<"Rock"<<endl;
}
if(option == 'P'){
cout<<"Paper"<<endl;
}
if(option == 'S'){
cout<<"Scissor"<<endl;
}
}
int main(){
char uchoice; //users choice
uchoice = useroption();
//computer choice
char cchoice;
cchoice = getcomputeroption();
//shows user choice
cout<<"User choice is: "<<endl;
showoptions(uchoice);
//shows computer choice
cout<<"Computer choice is: "<<endl;
showoptions(cchoice);
//choose winner
choosewinner(uchoice,cchoice);
}