% -----------------------------------------------------
% dlglengthunitconversion.m
% -----------------------------------------------------
% Write a program that asks the user to input a length in meters,
% creates a dialog box with options to convert given length to feet or 
% yards and uses a switch case statement to complete the 
% unit conversion. 
% -----------------------------------------------------
% Notes: None. 
% -----------------------------------------------------
% Copyright and license details available at matlabmarina.com
%------------------------------------------------------

clear;
clc;

% read in length in meters
meters = input('Enter length in meters : ');

% menu command for conversion
% Note: used questdlg as menu is no longer recommended
userselection = questdlg('Select units to convert to','Menu','feet','yards','feet');

if strcmp(userselection,'feet')
    choice = 1;    
elseif strcmp(userselection,'yards')
    choice = 2;
else
    choice = 0;
end

% define the convertion ratios
ftRatio = 3.28084;
yrdRatio = 1.09361;

% convert to specified units
switch choice
    case 1
        result = meters * ftRatio;
        unitChoice = 'feet';
    case 2
        result = meters * yrdRatio;
        unitChoice = 'yards';
    otherwise
        result='Quit';
end

% display result based off choice
if choice==0
    disp('exited menu');
else
    fprintf('%.2f meters = %.5f %s\n',meters,result,unitChoice);
end
