-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3401568
commit 69c7104
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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; | ||
} |