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

253
Views
How to add default in every case in c++

how do i add default in every case? it does not allow me to do it like this and will error in the second default,

switch (select)
{
    
    case 1:
        here1:
        cout<<"statement"<<endl;
        
    default:
        cout<<"statement"<<endl;
        goto here1;         

        break;
        

    case 2:
        here2:
        cout<<"statement"<<endl;
        
    default:
        cout<<"statement"<<endl;
        goto here2;         

        break;
        

i need default inside every case, how am i gonna do that?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

it looks like you are trying to execute the same piece of code for every case so why can't you just do so.

default just works if "incase nothing works" and if something works default doesn't execute.

over 4 years ago · Santiago Trujillo Report

0

well you really cant do this because "default" considered as a case itself so you cant make two cases in one. but instead if you want so mimic it you can use an "if statement " with the condition you want.

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!