change switch loop to if

Trying to change this siwtch loop into an if. the problem is that I want to ´´break´´ after each switch but I couldn't work it out. tried with return; and return 0;

1
2
3
4
switch(x){
case '1': user.EntradaDatos(); user.LecturaDatos(); user.RutaArchivo(); system ("cls"); goto Menu; break; 
case '2': user.Lectura(); break; 
case '3': exit(1); break; default: system ("cls"); goto Menu; break; }}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 if (x==1)
 {
  user.EntradaDatos();
user.LecturaDatos();
 user.RutaArchivo();
 system ("cls");
goto Menu;

  }

else if (x==2)
{
    user.Lectura();

  }

else (x==3){
            exit(1);


    system ("cls");


  }
    return 0;
}
You can't put a goto statement and then a break, because the goto will already have changed where you are executing code from. So, get rid of your goto statements.
In fact, get rid of goto statements altogether!
closed account (zA9T0pDG)
I've not done any C++ in awhile, but that else shouldn't work or if it does it isn't good practice. Also you have an exit call and then immediately after that you have a system call (but it isn't like that in your switch). And Mats is correct... using goto isn't a good idea either.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
if (x==1){
    user.EntradaDatos();
    user.LecturaDatos();
    user.RutaArchivo();
    system ("cls");
    goto Menu;
}

else if (x==2){
    user.Lectura();

}
else if(x==3){
    exit(1);
}
else{
    system ("cls"); 
    goto Menu;
}

return 0;
Topic archived. No new replies allowed.