# Math Help - Matlab Help!

1. ## Matlab Help!

need to create a program that will help me solve the following problem.

Long Term Parking
first hour is $1 and each additional hour or fraction thereof is$1.
daily maximum $6 Weekly maximum$42

Short Term Parking
first 30 mins are free and each additional 20 minutes or fraction thereof is $1. daily maximum$25

the program has to ask the user the following:
Which lot are you using?
how many weeks, hours, days and minutes did you park?

the program should then calculate the parking bill.

2. Originally Posted by lvelazquez83
need to create a program that will help me solve the following problem.

Long Term Parking
first hour is $1 and each additional hour or fraction thereof is$1.
daily maximum $6 Weekly maximum$42

Short Term Parking
first 30 mins are free and each additional 20 minutes or fraction thereof is $1. daily maximum$25

the program has to ask the user the following:
Which lot are you using?
how many weeks, hours, days and minutes did you park?

the program should then calculate the parking bill.
So what have you done so far?

CB

3. all i have is the following which i dont even know if its the right place to start.

Lot = input ('Which lot are you using? ')
switch lot
case (long term)

case (short term)

i honestly don't know where to go from here. i want the program to ask the user how many weeks, hours, days and minutes they were in that particular lot after they chose short/long term parking. any suggestions?

4. Originally Posted by lvelazquez83
all i have is the following which i dont even know if its the right place to start.

Lot = input ('Which lot are you using? ')
switch lot
case (long term)

case (short term)

i honestly don't know where to go from here. i want the program to ask the user how many weeks, hours, days and minutes they were in that particular lot after they chose short/long term parking. any suggestions?
Try running this code:

Code:
OK=0;
while (OK==0)
Lot = input ('Which lot are you using? ')
switch lot
case (long term)
disp('long term')
OK=1;
case (short term)
disp('short term')
OK=1;
otherwise
disp('try again')
end
end

CB

5. i tried using the following code you recommended but i keep getting an error.

OK=0;
while (OK==0)
Lot = input (
'Which lot are you using? ')
switch lot
case ('long term')
disp(
'long term')
OK=1;
case ('short term')
disp(
'short term')
OK=1;
otherwise
disp('try again')
end
end

how will this answer the question provided. I think i need a loop somewhere in here. also, how do i add so it asks the user how many weeks, days, hours and minutes?

6. this is the current code i am working with but its not exactly what i am looking for:

Lot = input ('Which lot are you using? ','s')
switch Lot
case ('long term')
weeks = input ('How many weeks? ','s')
switch weeks
case ('2')
total = 2.*42
days = input ('How many days? ','s')
switch days
case ('2')
total = 2.*6
hours = input ('How many hours? ','s')
switch hours
case ('2')
total = 2.*1
FinalBill = [weeks + days + hours]
end
end
end
end

i need it to be able to allow me to enter ANY number of weeks, days and hours and give me the correct calculation. any suggestions?

7. Originally Posted by lvelazquez83
this is the current code i am working with but its not exactly what i am looking for:

Lot = input ('Which lot are you using? ','s')
switch Lot
case ('long term')
weeks = input ('How many weeks? ','s')
switch weeks
case ('2')
total = 2.*42
days = input ('How many days? ','s')
switch days
case ('2')
total = 2.*6
hours = input ('How many hours? ','s')
switch hours
case ('2')
total = 2.*1
FinalBill = [weeks + days + hours]
end
end
end
end

i need it to be able to allow me to enter ANY number of weeks, days and hours and give me the correct calculation. any suggestions?
Make the input numeric:

XX=input('How many XXs?');

Also try:

>>help input

CB

8. i tried using the XX=input ('how many XX's?)

but i am not understanding exactly how you would like me to input this. I need for the user to type in 1 week or 2 weeks or 3 weeks etc... and then give the total for how much it would cost for those amounts of weeks (each week is 42 for the long term lot). that's also another thing..i need for the user to be able to select which lot and depending on which lot is chosen how much each week is.

9. Originally Posted by lvelazquez83
i tried using the XX=input ('how many XX's?)

but i am not understanding exactly how you would like me to input this. I need for the user to type in 1 week or 2 weeks or 3 weeks etc... and then give the total for how much it would cost for those amounts of weeks (each week is 42 for the long term lot). that's also another thing..i need for the user to be able to select which lot and depending on which lot is chosen how much each week is.
Is this explicit enough?

weeks = input ('How many weeks? )

Now weeks is a number.

As I said before type "help input" at the command prompt.

CB

10. this is my current m-file and it works! but the only thing is how do i make it that it asks these questions for each lot (short and long term)?

weeks = input (
'how many weeks? ')
switch weeks
case 1
total = 42.00;
otherwise
total = 42.00.*weeks;
end
fprintf ('your total is $%5.2f \n', total) days = input ( 'how many days? ') switch days case 1 totals = 6.00; otherwise totals = 6.00.*days; end fprintf ('your total is$%5.2f\n', totals)
hours = input (
'how many hours? ')
switch hours
case 1
totalss = 1.00;
otherwise
totalss = 1.00.*hours;
end
fprintf ('your total is $%5.2f\n\n', totalss) fprintf ( 'your total bill is$%5.2f\n', total+totals+totalss)

11. Originally Posted by lvelazquez83
this is my current m-file and it works! but the only thing is how do i make it that it asks these questions for each lot (short and long term)?

weeks = input (
'how many weeks? ')
switch weeks
case 1
total = 42.00;
otherwise
total = 42.00.*weeks;
end
fprintf ('your total is $%5.2f \n', total) days = input ( 'how many days? ') switch days case 1 totals = 6.00; otherwise totals = 6.00.*days; end fprintf ('your total is$%5.2f\n', totals)
hours = input (
'how many hours? ')
switch hours
case 1
totalss = 1.00;
otherwise
totalss = 1.00.*hours;
end
fprintf ('your total is $%5.2f\n\n', totalss) fprintf ( 'your total bill is$%5.2f\n', total+totals+totalss)
Duplicate the code adding long and sort term to the prompt strings or use a loop

CB

12. i am not familiar with the loop function. please assist me with that.

13. ok i figured it out!!!! i just added a "break" in between long term and short term.

lot = input ('which lot are you using? ','s')
switch lot
case ('long term');
weeks = input ('how many weeks? ')
switch weeks
case 1
wk = 42.00;
otherwise
wk = 42.00.*weeks;
end
fprintf ('your total is $%5.2f \n', wk) days = input ('how many days? ') switch days case 1 dy = 6.00; otherwise dy = 6.00.*days; end fprintf ('your total is$%5.2f\n', dy)
hours = input ('how many hours? ')
switch hours
case 1
hr = 1.00;
otherwise
hr = 1.00.*hours;
end
fprintf ('your total is $%5.2f\n\n', hr) fprintf ('your total bill is$%5.2f\n', wk+dy+hr)
break
switch lot
case ('short term');
end
end
days = input ('how many days? ')
switch days
case 1
day = 25.00;
otherwise
day = 25.00.*days;
end
fprintf ('your total is $%5.2f\n', day) hours = input ('how many hours? ') switch hours case 1 hour = 1.00; otherwise hour = 1.00.*hours; end fprintf ('your total is$%5.2f\n\n', hour)
fprintf ('your total bill is $%5.2f\n', day+hour) the problem is now with the following. in long term parking the first hour is$1.00 and each additional hour or fraction thereof is $1.00. how do i make matlab do this??? so if it is 1 hour and 1second it needs to equal$2.00.

and in short term parking the first 30 minutes is free and each additional 20 minutes or fraction thereof is $1.00. so if it is 31 minutes it needs to be$1.00.