DEV Community

May Do
May Do

Posted on

Simple Console Rock, Paper, Scissors in C++

This program is a simple rock, paper, scissors game where the player has to choose one of the three options to beat the computer. The computer will generate a random option by creating a number to indicate that option. 1 will be 'rock', 2 will be 'paper', and 3 will be 'scissors'. The expect outcome should look like this:
Alt Text

Before we begin, let's set the values of rock, paper, and scissors to a number like so:Alt Text

Now, let's make an options board. This will allow the user to pick between rock, paper, or scissors. Print out the options for the player to pick like this:
Alt Text

Next, we have to let the user pick and display their choice. We're displaying their number by comparing user value to our set constant values.
Alt Text

Once we have the user's choice, we need the get the computer's choice to see who is going to win. To do this we're going to randomly generate a number between 1-3 and display the computer's choice.
Alt Text

With both choices, we're ready to compare them and see who is the winner! Make a function that will determine all outcomes. Rock will beat scissors, scissors will beat paper, and paper will beat rocks. We should display the outcome if the computer or user wins. Don't forget to display a tie if both choices match.
Alt Text

And that's it! Those were the basic steps into making a rock, paper, scissors game in C++. All the code that was used for the program looks like this:
Alt Text

Top comments (3)

Collapse
 
kevin_david_k profile image
Kevin David

Why you didn't share the code?

Collapse
 
snjjay profile image
James

This answer looks good to me
kodlogs.com/38773/rock-paper-sciss...

Collapse
 
hexmcoder911 profile image
Mahmood Khan

THIS CODE REALLY HELPED ME A LOT! TYSM FOR THE CODE