ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am a newbie c++ programmer. I created a simple numbered menu, i get the users choice and based on that choice it calls the appropriate function. Once that function completes the program ends. I want it to reload the menu after the function finishes. How would i do this? The menu is in main(). I tried using a do loop to reload the menu when the function returns control to main but when the user enters the q to quit the programme goes into an infinite loop. Please help.
int main( )
{
LABEL:
int choice = drawMenu( );
switch(choice)
{
case 1:
//do something.
goto LABEL;
case 2:
//do something...
goto LABEL;
case 3: //suppose this is exit
break;
}
return 0;
}
it's late and i may have misread your post, but you could do something like this.
Code:
int main()
{
char choice;
//put your choices here
cout << "CHOICE GOES HERE" << endl;
cin >> choice;
//now you can just do a while until the user puts in a 'q'
while (choice != "q")
{
if (choice == "a")
{
//whatever you want to do
}
//do that same thing for all
//now just do another prompt for choices
cout << "CHOICES" << endl;
cin >> choices;
}
return 0;
}
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.