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.

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

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.

The C++ function, that compares both the choices, works based on the following criteria.
- Rock beats scissors as it smashes Scissors.
- Scissors beats paper as it cuts Papers
- Paper beats rocks as it wraps the Rock.
- 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).

Master modern programming with Beginning C++17 – your gateway to building powerful, efficient, and future-ready applications!
View on Amazon
The game gained international popularity in the 20th century, spreading to Western countries.