Menu C++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Menu C++

Output Example: MAIN MENU 1) Play 2) info 3) Exit If I want to let’s say go to info, how do I leave that menu and appear on the info window. With info being: //info 2) EXIT //returns to main menu PLEASE HELP

18th May 2019, 12:05 PM
Marin
Marin - avatar
5 Answers
+ 5
Use goto statement You want to go back to main menu so add label to begging of program 👍 When user goes to 2)info you are going to show a option 3)Exit In this info tab write a goto statement Sample structure of program : label_main: 1.Main Menu 2.user input to go to required tab i.e Play info or Exit. lable_play: //label for goto 3.Play tab 4.info tab structure { int i; printf("input 1 to go back to main menu and 2 to go into play tab\n"): scanf("%d",&i); if(i==1) goto label_main; else if(i==2) goto lable_play; /*you can use more complex if else structures if you want to extend your menu options */ I also used goto in one of my codes but unfortunately SL compiler does not allow runtime input ...haha */ /*my code as reference (it might help you 😁*/ /*start reading from line no 82 you'll understand */ https://code.sololearn.com/cMVpuE3TAUn7/?ref=app
18th May 2019, 1:16 PM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
+ 5
Marin if you get any problem you can direct message me.. I know you are working with cpp but goto is valid in it also //like c
18th May 2019, 1:22 PM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
+ 1
use switch or if-else statements for different choices. and then call the method which u chose. u can use system("cls") command to clear the screen(only works in windows)
18th May 2019, 1:03 PM
kiRA
kiRA - avatar
+ 1
THANKS
18th May 2019, 1:21 PM
Marin
Marin - avatar
+ 1
🇮🇳Omkar🕉 thanks for help, I will DM you if something’s bugging me
18th May 2019, 1:24 PM
Marin
Marin - avatar