Help Writting a program

2 vues (au cours des 30 derniers jours)
Juan Alvarez
Juan Alvarez le 6 Déc 2011
I need to write a program that will give the user a choice to pick between two parking lots. short term and long term. depending on the parking lot they pick the next question would how many weeks, hours, days and minutes did you park? and ultimetly give the user the bill... the rates are:
Short term: first 30 minutes are free each additional 20 minutes from there is $1 daily maximum $25
Long term: first hour is $1 and each additional hour is $1 daily maximum $6 weekley maximum $42
I've been using if, and elseif. i have tried while loops as well...any suggestions?
THANK YOU
  2 commentaires
Paulo Silva
Paulo Silva le 6 Déc 2011
you want dialog menu boxes or just command line text?
Jan
Jan le 6 Déc 2011
Please post, what you have done so far and which problems occurred.

Connectez-vous pour commenter.

Réponses (1)

Sean de Wolski
Sean de Wolski le 6 Déc 2011
Don't think about using if elseif. Think about what the goal is - take a whiteboard/chalkboard/scrap paper and write out how it will work. $6*xdays+$1*xhours+etc. Pseudocode will really help you.
Once you have that structure figured out, then decide how you tell a computer to do it. And I'll give you a hint: You don't need if/elseif/while/for. This is basic addition and multiplication.
  3 commentaires
Paulo Silva
Paulo Silva le 6 Déc 2011
yea where's that picture, it was very nice, please bring it back :)
Paulo Silva
Paulo Silva le 6 Déc 2011
Just in case the user really wants some kind of simple interface where's one example
t=input('[L]ong or [S]hort term?','s')
if strcmp(t,'L')
disp('The user chooses Long term')
%set some variables
elseif strcmp(t,'S')
disp('The user chooses Short term')
%set some variables
else
disp('Unknown answer')
return %ohhh no, something went wrong, lets terminate the code now
end
d=input('How many days?');
h=input('How many hours?');
m=input('How many minutes?');
%now you can apply the formula to calculate the cost based on the user data

Connectez-vous pour commenter.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by