help with simple program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • drewskee
    New Member
    • Oct 2007
    • 1

    help with simple program

    the following program prompts the user with the following menu :

    What would you like to do?
    1.print the contents of the database
    2.find all the songs on a particular album
    3.quit
    Please enter 1, 2, or 3.



    Everything works fine but i cannot figure out how to keep prompting the user with this menu after each input. for example, if u run the program and type in 1 the program ends. how do i keep the prompt up?

    Heres a section of my code...





    [CODE=java] int choice;
    choice = Console.readInt (
    "What would you like to do?\n"
    + "1. print the contents of the database\n"
    + "2. find all the songs on a particular album\n"
    + "3. quit\n"
    + "Please enter 1, 2, or 3.\n");



    if (choice==1)

    {

    int c = 0;
    while (c < count)

    {

    System.out.prin tln(songs[c] + "--" + artists[c] + "--" +
    albums[c] + "--" + years[c] + "--" + comments[c]);
    c = c + 1;

    }

    }


    else if (choice==2)


    {

    String albumschoice = Console.readStr ing("Enter album");
    albums[0]="jagged little pill"; songs[0]="You oughta know, Head over feet, and You learn";
    albums[1]="made in heaven"; songs[1]="heaven for everyone";
    albums[2]="zooropa"; songs[2]="stay (far away, so close!)";
    int i=0;
    char found = 'n';
    while (found =='n'&& i<=2)
    {

    if (albumschoice.e quals(albums[i]) )
    {
    System.out.prin tln("The songs for " +albums[i] + " are " +songs[i]);
    found = 'y';



    }
    else
    {
    i = i+1;
    }
    }

    if (found =='n')
    {
    System.out.prin tln(albumschoic e+ "is not in the database");


    }

    }

    else if (choice==3)
    System.out.prin tln("Have a nice day!");


    }

    }[/CODE]

    ...thanks
    Last edited by Ganon11; Oct 17 '07, 11:22 PM. Reason: Please use the [CODE] tags provided.
  • Ganon11
    Recognized Expert Specialist
    • Oct 2006
    • 3651

    #2
    So you would like to keep showing the dialogue repeatedly...th at suggests to me you use a loop.

    When do you want this loop to finish? When the user enters 3 to quit.

    So I would create a loop that continues executing until the user enters 3 for his/her selection.

    Comment

    Working...