-
Notifications
You must be signed in to change notification settings - Fork 375
Expand file tree
/
Copy pathRPSLS_wako_solution
More file actions
98 lines (81 loc) · 1.89 KB
/
RPSLS_wako_solution
File metadata and controls
98 lines (81 loc) · 1.89 KB
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
#include <iostream>
#include <stdlib.h>
using namespace std;
/*
This program:
Prompts the user to select either Rock, Paper, Scissors, Lizard, or Spock.
Instructs the computer to randomly select either Rock, Paper, Scissors, Lizard, or Spock.
Compares the user’s choice and the computer’s choice and determine the winner.
Informs the user who the winner is.
*/
int main() {
srand (time(NULL));
int computer = rand() % 5 + 1;
int user = 0;
cout << "====================\n";
cout << "rock paper scissors!\n";
cout << "====================\n";
cout << "1) ✊🏾\n";
cout << "2) ✋🏾\n";
cout << "3) ✌🏾\n";
cout << "4) 🦎\n";
cout << "5) 🖖🏾\n";
cout << "shoot! ";
cin >> user;
cout << "You chose ";
switch (user) {
case 1:
cout << "rock";
break;
case 2:
cout << "paper";
break;
case 3:
cout << "scissors";
break;
case 4:
cout << "lizard";
break;
case 5:
cout << "spock";
break;
default:
cout << "invalid choice";
break;
}
cout << ".\n";
cout << "The computer chose ";
switch (computer) {
case 1:
cout << "rock";
break;
case 2:
cout << "paper";
break;
case 3:
cout << "scissors";
break;
case 4:
cout << "lizard";
break;
case 5:
cout << "spock";
break;
}
cout << ".\n";
if (user == computer) {
cout << "Tie game!\n";
} else if (user == 1 && (computer == 3 || computer == 4)) {
cout << "You win!\n";
} else if (user == 2 && (computer == 1 || computer == 5)) {
cout << "You win!\n";
} else if (user == 3 && (computer == 2 || computer == 4)) {
cout << "You win!\n";
} else if (user == 4 && (computer == 2 || computer == 5)) {
cout << "You win!\n";
} else if (user == 5 && (computer == 1 || computer == 3)) {
cout << "You win!\n";
} else {
cout << "Computer wins!\n";
}
}