terminating a script with a quit comand
Mostrar comentarios más antiguos
I have been told to make a script that will evaluate a string, and at the end it must ask the user if they are sure they want to quit if yes then quit if no then rerun the switch.
this is an example of what i need it to look like for choice 7:
Please choose an option:
1. Length
2. First letter
3. Last letter
4. Reverse
5. All
6. Enter a new string
7. Quit
Choice: 7
Are you sure you would like to quit (Yes/No)? n
Please choose an option:
1. Length
2. First letter
3. Last letter
4. Reverse
5. All
6. Enter a new string
7. Quit
Choice: 7
Are you sure you would like to quit (Yes/No)? y
Quitting program
>>
my code looks like:
clear; clc; close all;
choice = input('please give a "string"(PHRASE) to be evaluated: ', 's');
%this is a function that i created that evaluates the string.
[length firstLetter lastLetter reverse all] = singletary6(choice);
%function [stringLength, firstLetter, lastLetter, reverse, all] = singletary6(str)
%if isempty(str)
% stringLength = 0;
% firstLetter = '';
% lastLetter = '';
% reverse = '';
% all = '';
%else ~isempty(str);
% stringLength = length(str);
% firstLetter = str(1);
% lastLetter = str(length(str));
% reverse = str(end:-1:1);
% all = str;
%end
%end
disp(choice)
menu = sprintf('1. length\n2. First letter\n3. Last Letter\n4. Reverse\n5. All\n6. Enter a new String\n7. Quit\n');
fprintf('1. length\n2. First letter\n3. Last Letter\n4. Reverse\n5. All\n6. Enter a new String\n7. Quit\n');
choose = input('Choose a comand from 1-7:');
while choose <= 7
switch choose
case 1
length
disp(menu)
choose = input('Choose a comand from 1-7:');
case 2
firstLetter
disp(menu)
choose = input('Choose a comand from 1-7:');
case 3
lastLetter
disp(menu)
choose = input('Choose a comand from 1-7:');
case 4
reverse
disp(menu)
choose = input('Choose a comand from 1-7:');
case 5
all
disp(menu)
choose = input('Choose a comand from 1-7:');
case 6
choice = input('Enter a new String(phrase)', 's');
[length firstLetter lastLetter reverse all] = singletary6(choice);
fprintf('\n')
disp(menu)
choose = input('Choose a comand from 1-7:');
fprintf('\n')
case 7
disp('Quit')
button = sprintf('Ready to quit?\nYes\nNo\n');
switch button
case 'Yes',
disp('Exiting MATLAB');
%Save variables to matlab.mat
save
case 'No',
quit cancel;
end
end
end
%i know there is a lot of stuff here but wanted to give as much as possible to help with an answer.
1 comentario
SonOfAFather
el 4 de Oct. de 2012
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!