473,396 Members | 2,039 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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...





Expand|Select|Wrap|Line Numbers
  1.         int choice;
  2.         choice = Console.readInt( 
  3.                        "What would you like to do?\n" 
  4.                      + "1. print the contents of the database\n" 
  5.                      + "2. find all the songs on a particular album\n"
  6.                      + "3. quit\n"
  7.                      + "Please enter 1, 2, or 3.\n"); 
  8.  
  9.  
  10.  
  11.         if (choice==1)
  12.  
  13.         {
  14.  
  15.         int c = 0;
  16.         while (c < count) 
  17.  
  18.             {
  19.  
  20.             System.out.println(songs[c] + "--" + artists[c] + "--" +
  21.             albums[c] + "--" + years[c] + "--" + comments[c]);
  22.             c = c + 1;
  23.  
  24.              }
  25.  
  26.          }
  27.  
  28.  
  29.        else if (choice==2)
  30.  
  31.  
  32.         {
  33.  
  34.             String albumschoice = Console.readString("Enter album");
  35.             albums[0]="jagged little pill"; songs[0]="You oughta know, Head over feet, and You learn";
  36.             albums[1]="made in heaven"; songs[1]="heaven for everyone"; 
  37.             albums[2]="zooropa"; songs[2]="stay (far away, so close!)"; 
  38.             int i=0;
  39.             char found = 'n';
  40.             while (found =='n'&& i<=2)
  41.             {
  42.  
  43.                   if (albumschoice.equals(albums[i]) ) 
  44.                 {
  45.                     System.out.println("The songs for " +albums[i] + " are " +songs[i]);
  46.                     found = 'y';
  47.  
  48.  
  49.  
  50.                 }
  51.                 else
  52.                 {
  53.                     i = i+1;
  54.                 }
  55.             }
  56.  
  57.             if (found =='n')
  58.             {
  59.                     System.out.println(albumschoice+ "is not in the database");
  60.  
  61.  
  62.                 }
  63.  
  64.             }
  65.  
  66.          else if (choice==3)
  67.          System.out.println("Have a nice day!");
  68.  
  69.  
  70.     }
  71.  
  72. }
...thanks
Oct 17 '07 #1
1 994
Ganon11
3,652 Expert 2GB
So you would like to keep showing the dialogue repeatedly...that 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.
Oct 17 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

31
by: da Vinci | last post by:
OK, this has got to be a simple one and yet I cannot find the answer in my textbook. How can I get a simple pause after an output line, that simply waits for any key to be pressed to move on? ...
10
by: atlanta | last post by:
this is a simple C++ program to write. "Write a complete and functioning structured program that successfully compiles on Visual C++ 6, that uses two-dimensional array (5x5) that stores...
2
by: Vitali Gontsharuk | last post by:
Hi! I have a problem programming a simple client-server game, which is called pingpong ;-) The final program will first be started as a server (nr. 2) and then as a client. The client then...
2
by: Wally | last post by:
Is there a simple code for reading and transmitting infa red for the tv, vcr, dvd etc. I have a client who has limited/no use of her hands. I've purchased a tira-2 infa red receiver/transmitter...
8
by: pamelafluente | last post by:
I am beginning aspNet, I know well win apps. Need a simple and schematic code example to start work. This is what I need to accomplish: ---------------------- Given button and a TextBox on a...
16
by: pamelafluente | last post by:
I am still working with no success on that client/server problem. I need your help. I will submit simplified versions of my problem so we can see clearly what is going on. My model: A client...
6
by: toch3 | last post by:
i am writing a c program that is basically an address book. the only header we are using is #include<stdio.hwe are to use a global array, loops, and pointers. we are to have a menu at the...
5
by: dav3 | last post by:
I am by no means an ultra slick programmer and my problem solving skills.. well they leave much to be desired. That being said I have been working on the following problem for the past few days and...
1
by: astrogirl77 | last post by:
I'm new to C++ and am hoping to find help with coding a simple C program, am wanting to obtain code and functioning exe's. I code in an old version of Visual Basic 4.0, I have a simple app that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.