Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

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

  • 02-10-2012 08:17PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 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
Advertisement