Well, I'm trying to eliminate all the goto in my code, but I can't figure out a way of doing that if the command is inside a do/while loop. Any tips, guys? =)
**Ignore the system(). I'll add a substitute to call for it later... BUT... Feel free to comment how I can do that... =D
do {
label_1:
std::cout << "What do you wanna do?" << std::endl
<< "1 - Go pick the equipment." << std::endl
<< "2 - Take a look at the basement." << std::endl
<< "3 - Do nothing." << std::endl;
std::cin >> choice;
if (choice == 1) {
std::cout << "JHENNY: We are ready to go!" << std::endl;
}
elseif (choice == 2) {
std::cout << "JHENNY: Where are you going?!" << std::endl;
system ("pause");
goto label_1;
}
elseif (choice == 3) {
std::cout << "JHENNY: What are you waiting for?!" << std::endl;
system ("pause");
goto label_1;
}
} while (choice > 3);
Who tells you "permission denied"?
Can't be the compiler !?
In your case, the easiest thing is to set choice to something above 3 instead of the gotos, so that the while() condition is true after you exit the if() s.
So, you will stay in the loop.
Thank you new1! Doing by your way, it gives the expected result, but I have to alter the structure of all the choices...
Reading your comment, plexus, I noticed that if I only alter while (choice > 1) it also gives the expected result... =P
And it was the forum that showed me the message "permission denied"! Not the compiler!