Computer Science Canada

max limit

Author:  RENThead [ Fri Feb 23, 2007 1:22 pm ]
Post subject:  max limit

how do i make it so that an eqation in my program can only have one max anwser?

Quote:

var timee : real
var total : real
var basecharge : real := 1.50

put "Please type in how many minutes you were parked in the garage then press enter."
get timee


if timee <= 30 then
total := basecharge
elsif timee > 30 and timee <= 60 * 5 then
total := (timee - 30) / 30 * 1.25 + basecharge
elsif timee > 60 * 5 then
total := ceil ((timee / 60) - 5 * 1.50) + 1.50 + (5 * 2.1 * 1.50)
end if

put "this is what you should pay ", total : 0 : 2


how do i make it so that the person only has to pay 20.00 max

Author:  Cervantes [ Fri Feb 23, 2007 2:19 pm ]
Post subject:  RE:max limit

How about this:

code:

var maxcharge : real := 20.00
if timee <= 30 then
    total := basecharge
elsif timee > 30 and timee <= 60 * 5 then
    total := (timee - 30) / 30 * 1.25 + basecharge
elsif timee > 60 * 5 then
    total := maxcharge
end if


Maybe I don't understand exactly what you're trying to do.

Author:  Abstraction [ Fri Feb 23, 2007 5:35 pm ]
Post subject:  Re: max limit

I guess you could add something right before the output statement like this:

if total >= 20
then total := 20
end if

Author:  Clayton [ Fri Feb 23, 2007 5:46 pm ]
Post subject:  Re: max limit

which is what he did (albeit a bit shrouded). the

code:

if timee > 60 * 5 then
...
end if


translates into, if the time is greater than 5 hours, then the total is equal to 20


: