4 Replies Latest reply on Jan 14, 2014 10:55 AM by gwarmonger

Control Flow Question

I am a newer programmer and I am not sure I would translate this into code..

If the time is between 21-30 days, the cost is \$50. If it is more than 30 days, there is an additional charge of \$34 for each additional month.

31-60 days would calculate at 84,

61-90 days would calculate at 118

and so on.

Thanks!

• 1. Re: Control Flow Question

Something like this?  Firstly,  a loop to demonstrate we're getting the correct value on every day

<cfset cost = 50>

<cfloop index="day" from="21" to="120">

<cfset extraCost = ((day-1) \ 30) * 34>

<cfoutput>

#day# days, #extraCost + cost#<br>

</cfoutput>

</cfloop>

Then probably something more like the code you'll need

<cfset days = 61> <!--- or whatever --->

<cfset newCost = (((days-1) \ 30) * 34) + 50>

<cfoutput>#newCost#</cfoutput>

• 2. Re: Control Flow Question

Worked! (actually I didn't try the loop, just the bottom part worked). Thank you!

• 3. Re: Control Flow Question

Just be mindful that "a month" is not a set amount of time. It can range from 29-31 days.

• 4. Re: Control Flow Question

Indeed. My work says they want it set for 30 days but "That might change". So good for now at least!