1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Rep Power

    Not sure which type of loop to use

    As part of a project im doing, I want the user to input a choice from a menu(1,2,or3) if they pick one of these choices they get asked whether they want pick another item, if they pick yes they then pick another choice, if they pick no they leave this part of the screen. But I can't get the programm to keep running after they enter their choice for the 2nd time. I tried using a do while loop, but I got confused where to place "Do you want to order again". Here is my code for it.

    The code tags made my code look worse?
    public void yourChoice(){ String choicePizzaAsString; String continueAsString=""; int pizzaChoice; choicePizzaAsString=JOptionPane.showInputDialog("Please enter your choice:"); pizzaChoice=Integer.parseInt(choicePizzaAsString); if(pizzaChoice !=1 && pizzaChoice !=2 && pizzaChoice !=3) { choicePizzaAsString = JOptionPane.showInputDialog("Invalid choice-please re-enter"); } else { continueAsString=JOptionPane.showInputDialog("Would you like to order anything else y/n"); } if(continueAsString.equals("y")){ choicePizzaAsString = JOptionPane.showInputDialog("Invalid choice-please re-enter"); } else if(continueAsString.equals("n")){ JOptionPane.showMessageDialog(null,"Please select a pizza"); }}
  2. #2
  3. Daniel Schildsky
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Mar 2004
    KL, Malaysia.
    Rep Power

    Format your codes

    Could you please format your codes properly using the CODE tag? It is really hard for us to read your codes and to catch any syntax errors with missing braces.

    Please properly indent your codes to increase readability.
    When the programming world turns decent, the real world will turn upside down.

IMN logo majestic logo threadwatch logo seochat tools logo