Skip to main content
Inspiring
January 13, 2014
Question

Control Flow Question

  • January 13, 2014
  • 1 reply
  • 732 views

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!

This topic has been closed for replies.

1 reply

Participating Frequently
January 14, 2014

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>

Inspiring
January 14, 2014

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

Inspiring
January 14, 2014

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