-4

How to go back to menu using case in switch case without using GOTO command. So this is the sample:

while(1){
  printf("1: Basic Math\n2. Intermediate Math\n3. Advance Math");
  printf("Enter your choice: ");
  int choice;
  scanf("%d", &choice);

  switch(choice)
    int theChoices;
    case 1:
      printf("1. Add\n 2. Subtract\n3. Go back to menu");
      scanf("%d", &theChoices);

      switch (theChoices) {
         case 1:
           //calculation ...
         case 2:
           //calculation ...
         case 3:
           // Go Back to menu which is Basic math, Intermediate Math, Advance math
           // ***** I want to know how do i get back to the main menu. *****
    case 2:
    // ....
// ....................

So my question again is how do i get back to the menu using the case 3. When i try using the keyword break, it automatically close the program when i chose case 3. Please help.

Big. D
  • 31
  • 1
  • 7
  • `while ((option = show_menu_and_return_option()) != QUIT_OPTION) ... ` – Iharob Al Asimi May 28 '16 at 18:05
  • I'm voting to close this question as off-topic because it **shows no effort**. *Please try+search first*. – gsamaras May 28 '16 at 18:05
  • Your code is incomplete. Switch statement not closed. Duplicate `case 2:`. You don't show how you handle `case 1:` and `case 2:` which I presume, gives defined behavior. – user3078414 May 28 '16 at 18:10
  • sorry sir but how can u say it has no effort? i try all the methods and i cant do it. i tried searching also. so i created a stackoverflow account to help me with the problem. – Big. D May 28 '16 at 18:10
  • hi user. i got different problem. and i try to explain to the simplest like this to understand you all. :). i want to know how do i get back to the menu using the inner switch case. – Big. D May 28 '16 at 18:11

1 Answers1

1

Use continue; instead. It will jump out of all cases and continue executing code after them, which will make the program return to the first line after while (1). Don't forget to close each case with a break;.

ForceBru
  • 43,482
  • 10
  • 63
  • 98