Doing the first project.function that can return back to the previous menu. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Doing the first project.function that can return back to the previous menu.

I am writing a program that contains several programs operated through a switch statement. The user is prompted with a menu and chooses wich program to execute .my problem is,is there a way to return to the menu after the switch 's case is executed?? Thanks.

30th May 2020, 9:15 PM
Amal Gil
Amal Gil - avatar
11 Answers
+ 3
Simple example:- #include <stdio.h> int main(){ int flag = 1; int option; int option2; while(flag){ puts("Select from Options below:-"); puts("For funct 1 Enter 1"); puts("For funct 2 Enter 2"); puts("For funct 3 Enter 3"); puts("To Quit.... Enter 4"); scanf("%d", &option); switch(option){ case 1: while(op2!=4){ //4 is to return back print the new list scanf(option2) switch(option2) { case 1 :.. break; case 2 :.. break ; case 3:.. break; case 4: break ; } } break; case 2: //funct2(); break; case 3: //funct(3); break; case 4: flag = 0; } } return 0; }
31st May 2020, 9:30 PM
Anon Fox
Anon Fox - avatar
+ 5
,.., thank you
31st May 2020, 9:36 PM
Amal Gil
Amal Gil - avatar
+ 3
amal 01 glad i could help :3
31st May 2020, 9:37 PM
Anon Fox
Anon Fox - avatar
+ 2
rodwynnejones when flag =0 it displays the previous menu.????
31st May 2020, 6:37 AM
Amal Gil
Amal Gil - avatar
+ 2
>>>>This is the first menu: 1-Student environment. 2-teacher environment. 3-unversity environment. For example I am a student. So I will click on first choice."student envirement" When I clicked to the "student environment "it displays me another menu: 1-see the courses. 2-see your grades. 3-email your teacher . 4-look to your level. 5-return back. For example I clicked to the 5 th choice ,so it should return me the 1 st menu. How can I do it inside a function. Void return_back(){ //your code .......; .....; } This is what I am aiming to do. If anyone knows the answer please help me and thank you in advance.
31st May 2020, 6:55 AM
Amal Gil
Amal Gil - avatar
+ 2
hmmm gud question🤔, did you solve it?
31st May 2020, 8:26 PM
Anon Fox
Anon Fox - avatar
+ 2
,.., hmmm,honestly not yet
31st May 2020, 8:29 PM
Amal Gil
Amal Gil - avatar
+ 2
amal 01 hmm, amal as the first guy said, you put a flag where you wanna exit and repeat whenever exit option is not selected, but in your case you will have to use nested switches coz you have multiple lists
31st May 2020, 9:15 PM
Anon Fox
Anon Fox - avatar
+ 2
,.., Yes exactly, maybe I'm going to share to code in order to get an answer.
31st May 2020, 9:20 PM
Amal Gil
Amal Gil - avatar
+ 1
Simple example:- #include <stdio.h> int main(){ int flag = 1; int option; while(flag){ puts("Select from Options below:-"); puts("For funct 1 Enter 1"); puts("For funct 2 Enter 2"); puts("For funct 3 Enter 3"); puts("To Quit.... Enter 4"); scanf("%d", &option); switch(option){ case 1: //funct1(); break; case 2: //funct2(); break; case 3: //funct(3); break; case 4: flag = 0; } } return 0; }
30th May 2020, 10:33 PM
rodwynnejones
rodwynnejones - avatar
+ 1
Okay ,let me try please.
31st May 2020, 6:35 AM
Amal Gil
Amal Gil - avatar