#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
// Function to get the computer's choice
string getComputerChoice() {
int choice = rand() % 3; // Generates a number between 0 and 2
if (choice == 0) return "Rock";
if (choice == 1) return "Paper";
return "Scissors";
}
// Function to determine the winner
string determineWinner(string playerChoice, string computerChoice) {
if (playerChoice == computerChoice) {
return "It's a tie!";
} else if ((playerChoice == "Rock" && computerChoice == "Scissors") ||
(playerChoice == "Paper" && computerChoice == "Rock") ||
(playerChoice == "Scissors" && computerChoice == "Paper")) {
return "You win!";
} else {
return "Computer wins!";
}
}
int main() {
srand(static_cast<unsigned int>(time(0))); // Seed the random number generator
string playerChoice;
cout << "Enter Rock, Paper, or Scissors: ";
cin >> playerChoice;
// Convert player choice to the first letter capitalized format
playerChoice[0] = toupper(playerChoice[0]);
for (size_t i = 1; i < playerChoice.length(); ++i) {
playerChoice[i] = tolower(playerChoice[i]);
}
string computerChoice = getComputerChoice();
cout << "Computer chose: " << computerChoice << endl;
string result = determineWinner(playerChoice, computerChoice);
cout << result << endl;
return 0;
}