# Couple questions

• 03-22-2013, 07:55 PM
L2Code
Couple questions
How do I use if and else if to play a game of rock paper scissors?

JOptionPane.showInputDialog("Enter rock, paper, or scissors");
JOptionPane.showInputDialog("Enter rock, paper, or scissors");

Now after this I have to write the if statements but dont understand how to do so to make it work. So far one person enters one of the options then hits okay then the other person would have to do the same then hit okay. I then need the program to figure out who wins and pops up another Dialog box telling the winner.

My next problem is this (code below). I wrote code using if statements to order numbers in numerical order but the program doesnt run any of my JOptionPanes even though its not giving me any errors or anything. I understand there are other possible ways of ordering numbers but this is the way I have to do it right now. What's my problem?
Thanks!

if (number1 > number2)
if (number2 > number3)
JOptionPane.showMessageDialog(null," "+ number1 + "," + number2 + "," + number3);
else
if (number1 > number2)
if (number2 < number3)
JOptionPane.showMessageDialog(null," "+ number1 + "," + number3 + "," + number2);
else
if (number1 < number2)
if (number2 < number3)
JOptionPane.showMessageDialog(null," "+ number3 + "," + number2 + "," + number1);
else
if (number1 > number2)
if (number2 < number3)
if (number1 < number3)
JOptionPane.showMessageDialog(null," "+ number3 + "," + number1 + "," + number2);
else
if (number1 < number2)
if (number2 > number3)
if (number1 > number3)
JOptionPane.showMessageDialog(null," "+ number2 + "," + number1 + "," + number3);
else
if (number1 < number2)
if (number2 > number3)
if (number1 < number3)
JOptionPane.showMessageDialog(null," "+ number2 + "," + number3 + "," + number1);
• 03-22-2013, 08:35 PM
KevinWorkman
Re: Couple questions
My first advice is to use curly brackets and indentation to organize your if/else blocks better.
• 03-22-2013, 08:45 PM
L2Code
Re: Couple questions
Quote:

Originally Posted by KevinWorkman
My first advice is to use curly brackets and indentation to organize your if/else blocks better.

Well besides organization.......
• 03-22-2013, 08:49 PM
KevinWorkman
Re: Couple questions
Crossposted: Help my if statements!

I really can't help you until you fix your formatting.
• 03-22-2013, 09:32 PM
L2Code
Re: Couple questions
Quote:

Originally Posted by KevinWorkman
Crossposted: Help my if statements!

I really can't help you until you fix your formatting.

Got it! hahah.

Okay onto the rock,paper,scissors? I have no idea how to start if statements for that :(sweat):
• 03-22-2013, 09:33 PM
KevinWorkman
Re: Couple questions
Quote:

Originally Posted by L2Code
When I try adding curly brackets around each section it tells me there is a syntax error on the token else and to delete it.

Exactly. I think you're making a mistake with lining up your sections. Adding the brackets will clear that up.
• 03-22-2013, 09:46 PM
L2Code
Re: Couple questions
Is it suppose to work without the "else" in there? Because I tried to just delete them after I put the brackets in there because of the syntax error that was coming up and now it works ( or so it seems so far).
• 03-22-2013, 10:54 PM
KevinWorkman
Re: Couple questions
Quote:

Originally Posted by L2Code
Is it suppose to work without the "else" in there? Because I tried to just delete them after I put the brackets in there because of the syntax error that was coming up and now it works ( or so it seems so far).

I don't really know whether it's supposed to work or not- you tell us. Also, I suggest posting your updated code, so everybody is looking at the same thing.