MATLAB: Using a switch case to determine parking cost

else iffunctionif statementswitchcase

I'm wanting to create a function that houses a switch case code to determine the cost of parking based on predetermined rates. This is what I have so far, I am just needing to incorporate a commao nd that asks how long weeks, hours, days, and minutes the person parked. Any help is welcomed.
function parking_meter
%This function gives you the total cost of parking for airfair for 4 types of parking lots at Northwest Arkansas Regional the city you want to go to
cost=input('Enter the name of the lot you intend to park in. Short Term, Intermediate, Long Term, or Economy. Case sensitive. \n', 's')
switch cost
case 'Short Term'
time=input('input the duration you parked in minutes \n')
if 0<=time && time<=30
disp('Free for one day')
elseif 31<=time && time<=60
disp('$2.00')
elseif time >= 60
a_cost=time./60*1;
cost= 2+a_cost;
disp(cost) %How do you incorporate the daily maximum of $14
end
case 'Intermediate'
time=input('input the duration you parked in minutes \n')
if 0<=time && time<=30
disp('Free for one day')
elseif 31<=time && time<=60
disp('$2.00')
elseif time >= 60
a_cost=time./60*1;
cost= 2+a_cost;
disp(cost) %How do you incorporate the daily maximum of $8
case 'Long Term'
time=input('input the duration you parked in minutes \n')
if 0<=time && time<=30
disp('Free for one day')
elseif 31<=time && time<=60
disp('$2.00')
elseif time >= 60
a_cost=time./60*1;
cost= 2+a_cost;
disp(cost) %How do you incorporate the daily maximum of $7
case 'Economy'
time=input('input the duration you parked in minutes \n')
if 0<=time && time<=15
disp('Free')
elseif 16<=time && time<=60
disp('$2.00')
elseif time >= 60
a_cost=time./60*1;
cost= 2+a_cost;
disp(cost) %How do you incorporate the daily maximum of $5
otherwise
disp('Please select a valid parking lot.')
end

Best Answer

One option is to create an input dialog.
prompt = {'Number of weeks', 'Number of days', 'Hours', 'Minutes'};
dlgtitle = 'Enter estimated time';
dims = [1 45];
definput = {'0' '0' '0' '0'};
answer = inputdlg(prompt,dlgtitle,dims,definput);
Then you can convert the output (string) to numeric:
timeVec = cellfun(@str2double, answer);
timeVec(1) %number of weeks
timeVec(2) %number of days, etc.
Also, rather than using input(), you can better control the user's selection by using a list dialog.
[indx,tf] = listdlg('PromptString', 'Select the log you intend to park in', ...
'SelectionMode', 'Single',...
'Name', 'Parking', ...
'ListSize', [160, 100], ...
'ListString', {'Short Term', 'Intermediate', 'Long Term', 'Economy'});
190422 164415-Parking.jpg