+ 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
6 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
+ 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
+ 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)
+ 1
THANKS
+ 1
š®š³Omkarš thanks for help, I will DM you if somethingās bugging me