Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
madhavv-05 authored Jul 19, 2024
1 parent 3401568 commit 69c7104
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions stone_paper_scissors.cpp
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;
}

0 comments on commit 69c7104

Please sign in to comment.