-
Notifications
You must be signed in to change notification settings - Fork 4
/
exec4-10.cpp
36 lines (34 loc) · 1.05 KB
/
exec4-10.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
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
// rock-paper-scissors
int main() {
const vector<string> moves = {"rock", "paper", "scissors"};
int user_move, random;
cout << "Welcome to Rock-paper-scissors!\n";
cout << "Please enter your move (0 - rock, 1 - paper, 2 - scissors) and a random number\n";
while (cin >> user_move >> random) {
if (user_move < 0 || user_move > 2) {
cout << "invalid move\n";
continue;
}
int computer_move = int(100 * fabs(sin(random))) % 3;
cout << "Your move is " << moves[user_move]
<< ", computer's move is " << moves[computer_move] << ". ";
switch (user_move - computer_move) {
case 0:
cout << "Draw!\n";
break;
case -1: case 2:
cout << "You lose!\n";
break;
case -2: case 1:
cout << "You win!\n";
break;
}
}
cout << "Bye\n";
return 0;
}