rock paper scissors (tsz. rock paper scissorses)
#include <iostream> #include <cstdlib> #include <ctime> using namespace std; string getComputerChoice() { int randNum = rand() % 3; // 0 = rock, 1 = paper, 2 = scissors if (randNum == 0) return "rock"; else if (randNum == 1) return "paper"; else return "scissors"; } string getUserChoice() { string choice; cout << "Enter your choice (rock, paper, or scissors): "; cin >> choice; return choice; } string determineWinner(string user, string computer) { if (user == computer) return "It's a draw!"; if ((user == "rock" && computer == "scissors") || (user == "scissors" && computer == "paper") || (user == "paper" && computer == "rock")) { return "You win!"; } return "Computer wins!"; } int main() { srand(time(0)); // Initialize random seed string userChoice = getUserChoice(); string computerChoice = getComputerChoice(); cout << "Computer chose: " << computerChoice << endl; cout << determineWinner(userChoice, computerChoice) << endl; return 0; }