Joanne
Joanne Neal wrote:Your smallest charging time is 15 minutes, so why don't you work with 15 minute periods instead of hours and minutes.
Convert your hours and minutes to minutes as Carey suggested and then work out how many 15 minute periods there are in that number of minutes (use the % operator to do this).
You can then say
if there are four or less 15 minute periods parking is free
else if there are eight or less 15 minute periods parking is $10
else subtract 8 from the number of periods, multiply the result by 3, add 10 (for the first two hours) and you have your answer.
You might need to tinker a bit when the number of minutes isn't an exact multiple of 15, but this is just a case of adding an extra three dollars at the end.
That should certainly reduce the number of if statements you have.
dan dam wrote:i liked the idea.
thanks i will try do this
update.
Joanne Neal wrote:Your smallest charging time is 15 minutes, so why don't you work with 15 minute periods instead of hours and minutes.
Convert your hours and minutes to minutes as Carey suggested and then work out how many 15 minute periods there are in that number of minutes (use the % operator to do this).
You can then say
if there are four or less 15 minute periods parking is free
else if there are eight or less 15 minute periods parking is $10
else subtract 8 from the number of periods, multiply the result by 3, add 10 (for the first two hours) and you have your answer.
You might need to tinker a bit when the number of minutes isn't an exact multiple of 15, but this is just a case of adding an extra three dollars at the end.
That should certainly reduce the number of if statements you have.
i subtracted the entering minutes from the exit minutes and divide by 15 . thats give me thw periods.
its works until the number is dont divide by 15.
if i enter 13 00 and exit at 18 20
it should be charge of 52.
because the totall didnt divide by 15 it gives me wrong number of 50.
Carey Brown wrote:P.S. Post your current source code.
Carey Brown wrote:[
= ((minutes + 14) / 15 - 8) * 3 + 10
Dan Dam wrote:
Carey Brown wrote:[
= ((minutes + 14) / 15 - 8) * 3 + 10
yes. thats work for all the inputs. why did the " + 14 " fixed it ?
Dan Dam wrote:yes. thats work for all the inputs.
Joanne
Carey Brown wrote:formula was specifically to handle this part of the requirement:
from the 3 hour for every 15 minutes an additional fee of 3 dollars.
Joanne
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |