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

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

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

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"
@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 MATLAB 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!