Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

How to make an invalid option cause you to re-enter an option? Java

Options
  • 02-10-2012 8:17pm
    #1
    Registered Users Posts: 24


    I'm coding a voting system for school, and wondering how to make an invalid vote not count as one of 5 votes? As in, if a invalid vote is cast, 5 are still left to be made, not 4.

    How can I do this with the else statement which prints out the invalid option code?


    string Variable;

    Variable = JOptionPane.showInputDialog(blah);

    if(boolean) {
    code
    }

    else if

    else if

    else { JOptionPane.showMessageDialog(null, "You have entered an invalid option. Your vote has not been counted.");

    JOptionPane.showMessageDialog(null, "Please re-enter your vote.");


    How do I make the last statement repeat the string variable without counting as a vote?


Comments

  • Registered Users Posts: 891 ✭✭✭Mmmm_Lemony


    Brego wrote: »
    I'm coding a voting system for school, and wondering how to make an invalid vote not count as one of 5 votes? As in, if a invalid vote is cast, 5 are still left to be made, not 4.

    How can I do this with the else statement which prints out the invalid option code?


    string Variable;

    Variable = JOptionPane.showInputDialog(blah);

    if(boolean) {
    code
    }

    else if

    else if

    else { JOptionPane.showMessageDialog(null, "You have entered an invalid option. Your vote has not been counted.");

    JOptionPane.showMessageDialog(null, "Please re-enter your vote.");


    How do I make the last statement repeat the string variable without counting as a vote?

    Not sure if this is exactly what you are looking for but, If you declare and instantiate a boolean value such as
    boolean validVote = true;
    

    then you can have a do while loop.

    Do, as in display the input dialog, and repeat, while validVote is false.


Advertisement