Using a switch case to determine parking cost
Show older comments
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
Accepted Answer
More Answers (0)
Categories
Find more on Language Fundamentals in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
