• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need help with Rock paper Scissors code ASAP

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Andrew Erdman
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 17648
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 17648
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 17648
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 17648
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 17648
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Why am I so drawn to cherry pie? I can't seem to stop. Save me tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic