Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

343
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!