Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

How do I make a rock, paper, scissors, program?

+12 votes
asked Nov 15, 2022 by Carlos Medina (220 points)

2 Answers

+1 vote
answered Nov 16, 2022 by vivek morariya (160 points)
you can use the rand function with time so that every second it generates a random number and then use if else or switch case to determine when it should be rock paper and scissors make sure that the probability of getting any of them is equal for example you can use if the number is divisible by 3 to stone not divisible by 3 to paper divisible by 5 for scissors.
0 votes
answered Nov 16, 2022 by Peter Minarik (86,040 points)

First, you get the logic right:

  • There are two players (either two human, or one human, one machine -- or even two machine)
  • Both make a random pick of three possible choices: rock, paper, scissors. You can also think of these as numbers: 0, 1, 2
  • When the choices are made, comparisons are done:
    • If both picked the same, it's a tie
    • rock beats scissors
    • paper beats rock
    • scissors beat paper
  • Based on the comparison, a winner is selected

Then you chose a programming language and start implementing the logic. Use input and output functions and conditions to branch your code in the right path.

Here's some pseudo-code for you:

Choices: { rock, paper, scissors }
print("Rock/Paper/Scissor?")
userInput = readInput()
computerInput = random(Choice)
if (userInput == computerInput)
    print("It's a tie!")
else if (userInput > computerInput)
    print("You win!")
else
    print("Computer win!")

I hope this helps.

Do your implementation then post any specific questions if you're stuck. Good luck! :)

commented Dec 16, 2022 by lilly (100 points)
it didnt work somthing in line 5 is wrong
commented Dec 17, 2022 by Peter Minarik (86,040 points)
It's pseudocode, no programming language would be able to run it. It just gives you a general idea of what needs to be done.

You have to do your own implementation with the desired programming language.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...