Help Writting a program

2 views (last 30 days)
Juan Alvarez
Juan Alvarez on 6 Dec 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 Comments
Paulo Silva
Paulo Silva on 6 Dec 2011
you want dialog menu boxes or just command line text?
Jan
Jan on 6 Dec 2011
Please post, what you have done so far and which problems occurred.

Sign in to comment.

Answers (1)

Sean de Wolski
Sean de Wolski on 6 Dec 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 Comments
Paulo Silva
Paulo Silva on 6 Dec 2011
yea where's that picture, it was very nice, please bring it back :)
Paulo Silva
Paulo Silva on 6 Dec 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

Sign in to comment.

Categories

Find more on Loops and Conditional Statements 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!