Reference to a cleared variable lot. Error in parking (line 13) switch lot

1 view (last 30 days)
function cost = parking(lot,timeinminutes)
menu('Select your desired parking lot: ','L','S');
switch lot
case 'L'
disp('How long, in minutes, will you park?')
if timeinminutes<=60
cost=1;

Accepted Answer

Joseph Cheng
Joseph Cheng on 3 Jul 2014
Edited: Joseph Cheng on 3 Jul 2014
if lot is being defined within the function you don't need to have it as an input. as what ever you're putting in that variable "slot" will be overwritten immediately by the input();
How are you calling the parking() function from the main program?
  2 Comments
David
David on 3 Jul 2014
Ok thanks. So i edited my code as shown above but another error appears. What does this mean exactly?
"Reference to a cleared variable lot. Error in parking (line 13) switch lot"
Star Strider
Star Strider on 3 Jul 2014
@David —
1. The menu call needs an output.
2. If that’s the entirety of your code, you’re missing at least two end statements, one for the switch ... case block and one for the if block. Please post the entirety of the part of your code that is throwing the error.

Sign in to comment.

More Answers (0)

Categories

Find more on Historical Contests 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!