Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 max limit
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
RENThead




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: 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.
Abstraction




PostPosted: 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
Clayton




PostPosted: 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
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: