forked from 790hanu/Annex-qr-code-simulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRSP.cpp
92 lines (67 loc) · 1.65 KB
/
RSP.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
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
//template for c++
int main() {
srand(time(NULL));
int randomNumber = rand() % 3 + 1;
string answer;
int userAnswer;
for (;;) {
cin.clear();
cout << "rock, paper, or scissors? ";
getline(cin, answer);
if (!answer.compare("scissors") || !answer.compare("Scissors"))
{
userAnswer = 1;
break;
}
if (!answer.compare("rock") || !answer.compare("Rock"))
{
userAnswer = 2;
break;
}
if (!answer.compare("paper") || !answer.compare("Paper"))
{
userAnswer = 3;
break;
}
else {
cout << "Please enter a valid answer.\n";
}
} // infinite for loop to get user to enter valid answer
if (randomNumber == 1) {
if (userAnswer == 1) {
cout << "It's a tie! Computer chose scissors! ";
}
else if (userAnswer == 2) {
cout << "You WIN! The computer chose scissors!";
}
else if (userAnswer == 3) {
cout << "You LOSE! The computer chose scissors!";
}
} // result if computer chooses scissors
else if (randomNumber == 2) {
if (userAnswer == 1) {
cout << "You LOSE! The computer chose rock!";
}
else if (userAnswer == 2) {
cout << "It's a tie! The computer also chose rock!";
}
else if (userAnswer == 3) {
cout << "You WIN! The computer chose rock!";
}
} // result if computer chooses rock
else if (randomNumber == 3) {
if (userAnswer == 1) {
cout << "You WIN! The computer chose paper!";
}
else if (userAnswer == 2) {
cout << "You LOSE! The computer chose paper!";
}
else if (userAnswer == 3) {
cout << "It's a TIE! The computer chose paper!";
}
} // result if computer chooses paper
}