mercredi 6 mai 2020

Choose an option with switch-case and go back to menu (C)

I have this code for example :

   void example()  {
   int i,j,k;
   int sum = 0;
   int a;
   printf("Menu");
   printf("Enter 1 for first case or 0 to exit");
   scanf("%d" , &a);

switch(a){
    case 1:
        printf("first case");
        printf("now go back to Menu");
        break;}

case 0:
    exit(0);

    break;}

I would like to know if i choose the first case how i can go every time back to :

printf("Menu"); 

I dont want to call the example() function, i just want to go in this specific line.

Can i do this with switch-case statement or with something else?

Aucun commentaire:

Enregistrer un commentaire