rock paper scissor c++

Here's a sample C++ program for a rock-paper-scissors game:

#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;

int main() {
    char playerChoice, computerChoice;
    int computerNum;

    cout << "Enter your choice - 'r' for rock, 'p' for paper, 's' for scissors: ";
    cin >> playerChoice;

    srand(time(0));
    computerNum = rand() % 3 + 1;

    if (computerNum == 1) {
        computerChoice = 'r';
        cout << "Computer chose rock." << endl;
    } else if (computerNum == 2) {
        computerChoice = 'p';
        cout << "Computer chose paper." << endl;
    } else {
        computerChoice = 's';
        cout << "Computer chose scissors." << endl;
    }

    if (playerChoice == computerChoice) {
        cout << "It's a tie!" << endl;
    } else if ((playerChoice == 'r' && computerChoice == 's') || (playerChoice == 'p' && computerChoice == 'r') || (playerChoice == 's' && computerChoice == 'p')) {
        cout << "You win!" << endl;
    } else {
        cout << "Computer wins!" << endl;
    }

    return 0;
}

Explanation: 1. Include necessary libraries for input/output, random number generation, and time. 2. Define the main function. 3. Declare variables for player's choice, computer's choice, and a random number for the computer's choice. 4. Prompt the player to enter their choice. 5. Generate a random number for the computer's choice based on the current time. 6. Map the computer's random number to rock, paper, or scissors and display the choice. 7. Compare the player's choice with the computer's choice to determine the winner or a tie. 8. Return 0 to indicate successful execution of the program.