How to end a menu using breaks?

12 views (last 30 days)
Lourenço
Lourenço on 1 Nov 2012
I'm having issues on closing a menu in which I'm working, the problem is that if I work on the menu a little bit and then try to close it, it never ends program at the first try, I have to tell him to end twice in order for it to work
This is a university project and I'm not allowed to use the functions "quit", "beep" and "menu", so if anyone knows any other way to do it successfully I'd really apreciate.
Here is the main script:
while (true)
fprintf(' 1- Analyse data file \n 2- present mission's list by growning priority factor \n 3- Remove mission manually \n 4- Create report of mission's option \n 0- End program \n')
escolha = input('Choose the desired option: ');
switch escolha
case 1
fprintf('You have chosen option 1- Analyse data file \n')
fprintf('\n')
menu;
break
case 2
disp('You have chosen option 2- Present mission's list by growning priority factor')
fprintf('\n')
menu;
break
case 3
disp('You have chosen option 3- Remove mission manually')
fprintf('\n')
menu;
break
case 4
disp('You have chosen option 4- Create report of mission's option')
fprintf('\n')
Submenu
case 0
resposta = closeprogram;
if answer == '1'
break
elseif answer == '0'
menu;
break
end
otherwise
fprintf('\n')
disp('Input a valid option!');
menu
end
end
----------------------------------------------
Now this is the function to end program (option 0)
function resposta = closeprogram while true
resposta = input('Are you sure you want to end the program? \n[Y]es/[N]o: ' , 'S');
switch upper(resposta)
case 'S'
resposta = '1';
break
case 'N'
resposta = '0';
fprintf('\nReturning to the program:\n');
break
otherwise
fprintf('\nInvalid option \nType "Y" to confirm that you are leaving the program or "N" to return to the main menu.\n\n');
end
end
-----------------------------------------
This is the Submenu option 4, I'm not sure if this is where the error is so I'll just post it here either way
function Submenu
while (true)
disp('1 – Limit mission's list by minimal priority')
disp('2 – Generate report')
disp('0 - Return to the main menu')
escolha = input('Choose the desired option: ');
switch escolha
case 1
disp('You have chosen option 1 - Limit mission's list by minimal priority')
fprintf('\n')
menu;
break
case 2
disp('You have chosen option 2 - Generate report')
fprintf('\n')
menu;
break
case 0
disp('You have chosen option 0 - Return to the main menu')
fprintf('\n')
menu;
break
otherwise
disp('Error!! Choose a valid option.')
fprintf('\n')
Submenu;
break
end
end
------------------------------ This issue usually happens when I choose option 4, then option 0, then 0 again, what the program should do is go to the Submenu, then return to the main menu and close, but it never closes at the first try
Thank you for you attention

Answers (0)

Categories

Find more on Interactive Model Editing in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!