1 Replies - 567 Views - Last Post: 04 October 2012 - 10:05 AM Rate Topic: -----

#1 Epic800  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 99
  • Joined: 28-August 11

MATLAB Code?

Posted 03 October 2012 - 04:43 PM

I am trying to make my program display my menu until the user decides to input 7 and quit out the program. I am using a function to call the specific task also.

% Prompt user for input string
str = input('Please enter a string: ', 's');

% call of the function
[stringLength, firstLetter, lastLetter, reverse] = baker6(str);


% displays the menu and determines what option the user wants
list = fprintf('Please choose an option: \n 1. Length \n 2. First Letter \n 3. Last Letter \n 4. Reverse \n 5. All \n 6. Enter a new string \n 7. Quit');

menu = input(' \n Choice: ');

switch(menu)
    case {1}
        fprintf('The length of %s is %.0f ' ,str, baker6(stringLength));
    case {2}
        sprintf('The first letter of %c is %c ' ,str, baker6(firstLetter));
    case {3}
        sprintf('The last letter of %s is %s ' ,str, baker6(lastLetter))
    case {4}
        sprintf('The reverse of %s is ' , str, baker6(reverse))
    case {5}
        disp('Hello')       
    case {6}
        str = input('Please enter a new string: ' , 's');
    case {7}
        query = input('Are you sure you would like to quit? (Yes/No) ');
        
    otherwise
        disp(list)
end


This post has been edited by Epic800: 03 October 2012 - 04:44 PM


Is This A Good Question/Topic? 0
  • +

Replies To: MATLAB Code?

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10393
  • View blog
  • Posts: 38,459
  • Joined: 27-December 08

Re: MATLAB Code?

Posted 04 October 2012 - 10:05 AM

Take a look at using a while loop.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1