+ 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.
11 Respuestas
+ 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;
}
+ 5
,.., thank you
+ 3
amal 01 glad i could help :3
+ 2
rodwynnejones when flag =0 it displays the previous menu.????
+ 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.
+ 2
hmmm gud question🤔, did you solve it?
+ 2
,.., hmmm,honestly not yet
+ 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
+ 2
,.., Yes exactly, maybe I'm going to share to code in order to get an answer.
+ 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;
}
+ 1
Okay ,let me try please.