-
Notifications
You must be signed in to change notification settings - Fork 0
/
stone_paper_scissors.cpp
45 lines (37 loc) · 1.29 KB
/
stone_paper_scissors.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
#include <iostream>
#include <cstdlib>
#include <ctime>
int main() {
srand(static_cast<unsigned int>(time(0)));
int playerChoice, computerChoice;
std::cout << "Rock, Paper, Scissors Game!\n";
std::cout << "Enter your choice: \n";
std::cout << "1 for Rock\n";
std::cout << "2 for Paper\n";
std::cout << "3 for Scissors\n";
std::cin >> playerChoice;
computerChoice = rand() % 3 + 1;
std::cout << "You chose: ";
switch (playerChoice) {
case 1: std::cout << "Rock\n"; break;
case 2: std::cout << "Paper\n"; break;
case 3: std::cout << "Scissors\n"; break;
default: std::cout << "Invalid choice\n"; return 1;
}
std::cout << "Computer chose: ";
switch (computerChoice) {
case 1: std::cout << "Rock\n"; break;
case 2: std::cout << "Paper\n"; break;
case 3: std::cout << "Scissors\n"; break;
}
if (playerChoice == computerChoice) {
std::cout << "It's a tie!\n";
} else if ((playerChoice == 1 && computerChoice == 3) ||
(playerChoice == 2 && computerChoice == 1) ||
(playerChoice == 3 && computerChoice == 2)) {
std::cout << "You win!\n";
} else {
std::cout << "You lose!\n";
}
return 0;
}