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;

 Réponse acceptée

Joseph Cheng
Joseph Cheng le 3 Juil 2014
Modifié(e) : Joseph Cheng le 3 Juil 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 commentaires

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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB dans Centre d'aide et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by