필터 지우기
필터 지우기

Help Writting a program

조회 수: 1 (최근 30일)
Juan Alvarez
Juan Alvarez 2011년 12월 6일
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
Paulo Silva
Paulo Silva 2011년 12월 6일
you want dialog menu boxes or just command line text?
Jan
Jan 2011년 12월 6일
Please post, what you have done so far and which problems occurred.

댓글을 달려면 로그인하십시오.

답변 (1개)

Sean de Wolski
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
Paulo Silva 2011년 12월 6일
yea where's that picture, it was very nice, please bring it back :)
Paulo Silva
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 CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by