• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need help with Rock paper Scissors code ASAP  RSS feed

 
Andrew Erdman
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
 
Junilu Lacar
Sheriff
Posts: 11477
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • 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: 11477
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • 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: 11477
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • 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: 11477
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • 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: 11477
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • 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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!