Help Writting a program
조회 수: 1 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Sean de Wolski
2011년 12월 6일
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
Paulo Silva
2011년 12월 6일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!