Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

344
Visualizações
Why is my code expecting a primary expression in a switch case before curly brackets?

I am trying to use a switch case as a sort of menu selection for the user in my code. I have this enum list:

enum menuChoice {ADD = 1, REMOVE = 2, DISPLAY = 3, SEARCH = 4, RESULTS = 5, QUIT = 6};

Then I have this code:

        menuChoice switchChoice;
        Student student;

        cout << "1. Add\n" << "2. Remove\n" << "3. Display\n" << "4. Search\n";
        cout << "5. Results\n" << "6. Quit" << endl;

        for (int i = 0; i < 999; ++i)
        {
                cout << "Please enter choice:";

                cin >> userChoice;

                if (userChoice > 6 || userChoice < 1)
                {
                        cout << "Incorrect choice. Please enter again" << endl;
                }
                else
                {
                        break;
                }
        }

        switchChoice = static_cast<menuChoice>(userChoice);
        switch(switchChoice){

        case 1:
                add_Student(student);

                break;
        case 2:

                break;
        case 3:

                break;
        case 4:

                break;
        case 5:

                break;
        case 6:
                break;

        default:
        }

Which is kicking back this error:

 error: expected primary-expression before ‘}’ token

I am really scratching my head over this. What is the mistake here? How am I not implementing a primary expression? I know that you aren't supposed to pass types to switch parameters but this is an enum variable I'm passing. Some help on this would be greatly appreciated.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

default: } is a syntax error. The default label must be followed by a statement or a block. (This applies to any othe sort of label too).

For example it could be default: break; or default: ; or default: {} .

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda