Switch case help me please

Hello, when I run "option 1" in my switch case it, once i select the option the program executes the case but then ends; I'd like to know how to make it go back to my 'main menu' ?

~~ Please note that at this point I am only trying to make case 1 work

Thanks in advance

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
  #include<stdio.h>
#include<conio.h>
#include<cstdlib>
int main ()


{
	int choice;


	
	printf("*****************************\n");
	printf("**     Team Soulection     **\n");
	printf("*****************************\n");
	printf("** Press ENTER To Continue **\n");
	printf("*****************************\n");

	getch();
	
	printf("*****************************************************\n");
	printf("** 1. Find Discounted amount of your shopping bill **\n");
	printf("** 2. Print the table of any number entered        **\n");
	printf("** 3. Help manual for this app                     **\n");
	printf("** 4. Exit                                         **\n");
	printf("*****************************************************\n");
	
	
	printf("\n\n\n\n Your selection:  ");
	scanf("%d", &choice);
	
	
	switch (choice)
	{
	case 1:
			printf("Option 1");
			
			
		
				
		 	getch();
			break;
			
	case 2: 
				printf("Option 2");
				
			break;
	
	case 3: 
				printf("Option 3");
		
			break;
	
	
	case 4:
				printf("Option 4");
			
			break;
	
	default:
			printf("Not a valid choice");
	}
	

}
Last edited on
of course there is no loop. Also default needs a break;
How do I make a loop
http://www.cplusplus.com/doc/tutorial/control/

Specifically for your case, you might wanna pay extra special attention to the while or do while.

I would say do while because it's guaranteed to run the loop at least once until it meets the boolean condition.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include<stdio.h>
#include<conio.h>
#include<cstdlib>
int main ()


{
	int choice;

	

	printf("*****************************\n");
	printf("**     Team Soulection     **\n");
	printf("*****************************\n");
	printf("** Press ENTER To Continue **\n");
	printf("*****************************\n");

	getch();
	
	do
	{
	printf("\n\n");
	printf("*****************************************************\n");
	printf("** 1. Find Discounted amount of your shopping bill **\n");
	printf("** 2. Print the table of any number entered        **\n");
	printf("** 3. Help manual for this app                     **\n");
	printf("** 4. Exit                                         **\n");
	printf("*****************************************************\n");
	
	
	printf("\n\n\n\nYour selection:  ");
	scanf("%d", &choice);
	

	switch (choice)
	{
	case 1:
			printf("Option 1\nPress ENTER to return to menu");
			
			
			
			
		 	getch();
			break;
			
	case 2: 
				printf("Option 2");
			
			getch();
			break;
	
	case 3: 
				printf("Option 3");
			
			
			getch();
			break;
	
	
	case 4:
				printf("Option 4");
			
			
			getch();
			break;
	
	default:
			printf("Not a valid choice");
			getch();
			break;
	}
	
	}
	while (choice!=5);


	getch();

}


IT WORKS!! YAY I LOVE YOU GUYS
Last edited on
Topic archived. No new replies allowed.