first of all, im going to apologize for my bad english if there is, since im brazilian.
My question is:
I have read in various places the you should avoid using the GOTO statement at all costs when programming in C++. OK, but, in almost every of my programs I use about 10 GOTO statements because I think it is very useful, other people say otherwise. So im trying to end the habit of using GOTO, but, what can i use to replace this? I saw about using loops, such as do...while, while, for, if, functions and others. But I can't see how can I adapt the goto staments with those codes.
For example, this program:
cout << "Hello, insert 1 to continue on the program or 2 to exit it";
cin >> chose;
// I would normally use a if or switch stament here, so here it is
if (chose == 1)
cout << "The program will continue";
if (chose == 2)
if (chose != 1, 2)
goto invalid_value //Here is the villain
Get it? This of course is a very simple way to describe my problem, but for example, if in various parts of the program I have to insert 1 or 2 to do yada yada..., within or without a switch statement, how could i do the invalid_value "function" to be executed if i didn't put nor 1 or 2? What could I use in the place of GOTO?