This is a simple C++ program to demonstrate rock, paper, scissors game. In this game, players have to choose one of the three options to beat the opponent or the computer itself.

The following C++ code prints a simple menu showing three options to the user and then user can enter one of the options.

C++ code to print  rock, paper, scissors game menu

Below is the game menu which shows list of options to choose.

rock, paper, scissors game menu options

The C++ code generates a random choice by creating a character to indicate that option. Options are: r is for ‘rock’, p is for ‘paper’, and s is for ‘scissors’.

Once we have both the choices i.e. user’s choice and computer’s choice then our program compares both the choices to see who the winner is.

C++ code choosing the winner.

The C++ function, that compares both the choices, works based on the following criteria.

  1. Rock beats scissors as it smashes Scissors.
  2. Scissors beats paper as it cuts Papers
  3. Paper beats rocks as it wraps the Rock.
  4. Show a tie if both choices match.

Rock, Paper, Scissors Game C++ Source Code

Here is the full C++ source code for this game. Feel free to copy and paste this code into your course work/assignments and modify as necessary. In this code, computer’s choice is selected based on random number generator. We also use modulus operator and time seed to generate a different random numbers every time.

Facts about Rock, Paper and Scissors Game

The earliest known version of the game (shoushiling) might have roots in China, dating back to the Han Dynasty (approximately 206 BCE to 220 CE).

In Japan, the game is known as “jan-ken,” and it became popular during the Edo period (17th to 19th centuries).

The game gained international popularity in the 20th century, spreading to Western countries.