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?

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

2 Answers

+2 votes
answered Nov 16, 2022 by vivek morariya (180 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.
+1 vote
answered Nov 16, 2022 by Peter Minarik (101,340 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 (101,340 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.
commented Dec 11, 2024 by Tyler Adams (350 points)
Dam, what Peter Minarik said is insane, ultra Sigma. +92,610 aura
commented Dec 11, 2024 by Tyler Adams (350 points)
Dam, I just noticed this was two years ago. That is absolutely Wild, Dam. Lilly is now in the 8th grade. I hope you did not choose coding as an elective, hahahahahahahahaha.
commented Dec 11, 2024 by Tyler Adams (350 points)
It is with a sense of longing that I acknowledge the improbability of ever encountering this particular moment again in my life. The fleeting nature of experiences makes such moments all the more precious. Additionally, I am aware that this message might not reach you, yet I feel it is important to express my gratitude. You have truly brought a smile to my face and provided me with laughter during a time when it was much needed. Your ability to evoke joy is a wonderful gift, and I sincerely hope that each of you embarks on a journey that is filled with happiness, prosperity, and enriching experiences. Thank you for the delightful moments that I will carry with me.
commented Dec 11, 2024 by Tyler Adams (350 points)
edited Dec 11, 2024 by Tyler Adams
"Farewell, and I sincerely wish you a prosperous and fulfilling life ahead. May your future endeavors bring you success and satisfaction in all aspects."
commented Dec 11, 2024 by Tyler Adams (350 points)
If you’re interested in staying updated on my latest adventures and projects, I invite you to check out my YouTube channel, CrimsonCrewTY. On my channel, you’ll find a diverse range of videos that capture my experiences, creative endeavors, and insights into what I’m passionate about. Thank you for your interest and support—I appreciate it!
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...