Results 1 to 13 of 13

Math Help - Matlab Help!

  1. #1
    Junior Member
    Joined
    Jan 2010
    Posts
    38

    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.
    Last edited by mr fantastic; April 12th 2010 at 07:02 PM. Reason: Edit to post title
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by lvelazquez83 View Post
    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
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Junior Member
    Joined
    Jan 2010
    Posts
    38
    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?
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by lvelazquez83 View Post
    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
    Then add additional code to do the remaining processing

    CB
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Junior Member
    Joined
    Jan 2010
    Posts
    38
    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?
    Follow Math Help Forum on Facebook and Google+

  6. #6
    Junior Member
    Joined
    Jan 2010
    Posts
    38
    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?
    Last edited by lvelazquez83; April 13th 2010 at 09:24 PM.
    Follow Math Help Forum on Facebook and Google+

  7. #7
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by lvelazquez83 View Post
    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
    Follow Math Help Forum on Facebook and Google+

  8. #8
    Junior Member
    Joined
    Jan 2010
    Posts
    38
    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.
    Follow Math Help Forum on Facebook and Google+

  9. #9
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by lvelazquez83 View Post
    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
    Follow Math Help Forum on Facebook and Google+

  10. #10
    Junior Member
    Joined
    Jan 2010
    Posts
    38
    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)
    Follow Math Help Forum on Facebook and Google+

  11. #11
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by lvelazquez83 View Post
    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
    Follow Math Help Forum on Facebook and Google+

  12. #12
    Junior Member
    Joined
    Jan 2010
    Posts
    38
    i am not familiar with the loop function. please assist me with that.
    Follow Math Help Forum on Facebook and Google+

  13. #13
    Junior Member
    Joined
    Jan 2010
    Posts
    38
    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.
    Last edited by lvelazquez83; April 14th 2010 at 09:07 AM.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Matlab help
    Posted in the Math Software Forum
    Replies: 1
    Last Post: February 11th 2010, 02:59 AM
  2. Matlab FFT Help
    Posted in the Math Software Forum
    Replies: 0
    Last Post: June 3rd 2009, 12:48 PM
  3. help about ODE in matlab
    Posted in the Math Software Forum
    Replies: 1
    Last Post: May 31st 2009, 03:10 AM
  4. Matlab
    Posted in the Math Software Forum
    Replies: 0
    Last Post: November 6th 2008, 08:46 AM
  5. Matlab
    Posted in the Calculus Forum
    Replies: 3
    Last Post: August 20th 2008, 10:39 PM

Search Tags


/mathhelpforum @mathhelpforum