how to use a switch inside a switch?

0

In case, I can not choose the menu option to select difficulty, am I doing the correct way the switch inside a switch?

#include <stdio.h>
#include <stdlib.h>
#define TENTF 5
#define TENTD 3

int main()

{

    char opcao;
    int nome;

    printf("\n\t\t\t-------------------");
    printf("\n\t\t\t   JOGO DA FORCA");
    printf("\n\t\t\t-------------------");
    printf("\n\n\t\t\t1 - INICIAR PARTIDA");
    printf("\n\t\t\t2 - CONFIGURAR DIFICULDADE");
    printf("\n\t\t\t3 - SAIR");
    printf("\n\n\t\t\tOPCAO DESEJADA:");
    scanf("%c", &opcao);

    switch (opcao)
    {
        case '1':
            printf("\n\n\t\t\tINICIAR PARTIDA");
            break;

        case '2':
            printf("\n\n\t\t\tCONFIGURAR DIFICULDADE"); 
            printf("\n\n\t\t\t-------------------");
            printf("\n\t\t\t   JOGO DA FORCA");
            printf("\n\t\t\t-------------------");
            printf("\n\n\t\t\t F - FACIL");
            printf("\n\n\t\t\t D - DIFICIL");
            printf("\n\n\n\t\t\t V - VOLTAR");
            printf("\n\n\t\t\tOPCAO DESEJADA:");
            scanf("%c", &opcao);
            break;

            switch (opcao)

            {
                case 'F':
                    printf("\n\n\t\t\tCONFIGURAR DIFICULDADE"); 
                    printf("\n\t\t\t-------------------");
                    printf("\n\t\t\t   JOGO DA FORCA");
                    printf("\n\t\t\t-------------------");
                    printf("\n\n\t\t\t F - FACIL*");
                    printf("\n\n\t\t\t D - DIFICIL");
                    printf("\n\n\n\t\t\t V - VOLTAR");



                case 'D':
                    printf("\n\n\t\t\tCONFIGURAR DIFICULDADE"); 
                    printf("\n\t\t\t-------------------");
                    printf("\n\t\t\t   JOGO DA FORCA");
                    printf("\n\t\t\t-------------------");
                    printf("\n\n\t\t\t F - FACIL");
                    printf("\n\n\t\t\t D - DIFICIL*");
                    printf("\n\n\n\t\t\t V - VOLTAR");
                    break;

                case 'V':

                    printf("\n\t\t\t-------------------");
                    printf("\n\t\t\t   JOGO DA FORCA");
                    printf("\n\t\t\t-------------------");
                    printf("\n\n\t\t\t1 - INICIAR PARTIDA");
                    printf("\n\t\t\t2 - CONFIGURAR DIFICULDADE");
                    printf("\n\t\t\t3 - SAIR");
                    printf("\n\n\t\t\tOPCAO DESEJADA:");
                    scanf("%c", &opcao);
                    break;

                    }




        case '3':

            printf("\n\n\t\t\tSAIR");
            break;

        default:

            printf("\n\n\t\t\tDESCULPE, A OPCAO DIGITADA EH INVALIDA.");
            printf("\n\n\t\t\tOPCAO DESEJADA:");
            scanf("%c", &opcao);
            break;

    }

}
    
asked by anonymous 22.04.2016 / 21:53

2 answers

1

Try to put the second switch before the break.

case '2':
    printf("\n\n\t\t\tCONFIGURAR DIFICULDADE"); 
    printf("\n\n\t\t\t-------------------");
    printf("\n\t\t\t   JOGO DA FORCA");
    printf("\n\t\t\t-------------------");
    printf("\n\n\t\t\t F - FACIL");
    printf("\n\n\t\t\t D - DIFICIL");
    printf("\n\n\n\t\t\t V - VOLTAR");
    printf("\n\n\t\t\tOPCAO DESEJADA:");
    scanf("%c", &opcao);


    switch (opcao)
    {
        //cases...
    }

    break;
    
22.04.2016 / 21:57
0

If this is the path, then this switch will be a book:)

Use functions instead of sub-switches.

type before function main define:

void nomeDoQueFazNoSubSwitch() { 
    <coloque aqui o sub-switch>
};

and call it like this before the break:?

nomeDoQueFazNoSubSwitch();
    
23.04.2016 / 01:14