• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Control Flow Question

Explorer ,
Jan 13, 2014 Jan 13, 2014

Copy link to clipboard

Copied

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!

Views

535

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 14, 2014 Jan 14, 2014

Copy link to clipboard

Copied

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 14, 2014 Jan 14, 2014

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 14, 2014 Jan 14, 2014

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 14, 2014 Jan 14, 2014

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation