Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Need help with Rock paper Scissors code ASAP

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Andrew Erdman
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I might be missing a part of the end code for the wins or something. And I think it is in a loop because when you type rock or whatever it does not run. Any help is appreciated, thank you
 
Sheriff
Posts: 13549
223
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

Folks don't really respond to "ASAP" and "URGENT" messages, so you might as well EaseUp, pardner. We'll git to ya when we git to ya.
 
Junilu Lacar
Sheriff
Posts: 13549
223
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure you know what all the possible values that this line of code will assign to num2?

Maybe you should try to see for sure what all values num2 will get from this.
 
Junilu Lacar
Sheriff
Posts: 13549
223
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, look carefully at line 24:

If you're using an IDE like Eclipse or NetBeans and you used the keyboard shortcut Ctrl+Shift+F to format your code, it would have been more apparent. As it is now, that little bug is hiding at the end of the line.
 
Junilu Lacar
Sheriff
Posts: 13549
223
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And what exactly is it you think you're trying to do on lines 71-82? It looks like you are checking for a bunch of different condition but you're printing out the same message regardless. That doesn't seem logical.
 
Junilu Lacar
Sheriff
Posts: 13549
223
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check your prompt on line 21: you don't give an option for paper but you have two options for rock.

Here's a neat trick:

If you assign Rock=1, Paper=2, Scissors=3

Let:
p1 be the move player 1 makes
p2 be the move player 2 makes

Then:
result = (p1 - p2 + 3) % 3

0 -> tie
1 -> player 1 wins
2 -> player 2 wins
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!