Advertisement
Magnect

SWITCH

May 20th, 2019
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.82 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <conio.h>
  4.  
  5. void menu_1(int *sair);
  6. void menu_2(int *sair);
  7. void menu_3(int *sair);
  8.  
  9. void menu_3(int *sair){
  10.     char opcao;
  11.  
  12.     system("cls");
  13.     printf("============\n");
  14.     printf("   MENU 3\n");
  15.     printf("============\n");
  16.     printf("[1] AVANCAR\n");
  17.     printf("[2] VOLTAR\n");
  18.  
  19.     opcao = getch();
  20.  
  21.     switch(opcao){
  22.     case '1': //AVANCAR
  23.         printf("\nImpossivel avancar!");
  24.         getch();
  25.         menu_3(sair);
  26.         break;
  27.     case '2': //VOLTAR
  28.         menu_2(sair);
  29.         break;
  30.     default:
  31.         printf("\nOpcao invalida!");
  32.         getch();
  33.         menu_3(sair);
  34.         break;
  35.     }
  36. }
  37.  
  38. void menu_2(int *sair){
  39.     char opcao;
  40.  
  41.     system("cls");
  42.     printf("============\n");
  43.     printf("   MENU 2\n");
  44.     printf("============\n");
  45.     printf("[1] AVANCAR\n");
  46.     printf("[2] VOLTAR\n");
  47.  
  48.     opcao = getch();
  49.  
  50.     switch(opcao){
  51.     case '1': //AVANCAR
  52.         menu_3(sair);
  53.         break;
  54.     case '2': //VOLTAR
  55.         menu_1(sair);
  56.         break;
  57.     default:
  58.         printf("\nOpcao invalida!");
  59.         getch();
  60.         menu_2(sair);
  61.         break;
  62.     }
  63. }
  64.  
  65. void menu_1(int *sair){
  66.     char opcao;
  67.  
  68.     system("cls");
  69.     printf("============\n");
  70.     printf("   MENU 1\n");
  71.     printf("============\n");
  72.     printf("[1] AVANCAR\n");
  73.     printf("[2] ENCERRAR\n");
  74.  
  75.     opcao = getch();
  76.  
  77.     switch(opcao){
  78.     case '1': //AVANCAR
  79.         menu_2(sair);
  80.         break;
  81.     case '2': //ENCERRAR
  82.         *sair = 1;
  83.         printf("\nSaindo...\n");
  84.         break;
  85.     default:
  86.         printf("\nOpcao invalida!");
  87.         getch();
  88.         menu_1(sair);
  89.         break;
  90.     }
  91. }
  92.  
  93. int main(){
  94.     int sair = 0;
  95.  
  96.     do{
  97.         menu_1(&sair);
  98.     }while(sair != 1);
  99.  
  100.     return 0;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement