Skip to main content
claudes59463176
Participating Frequently
April 13, 2018
Answered

Simple program

  • April 13, 2018
  • 1 reply
  • 1015 views

Can someone help me write a simple program?

I want to create a program that allows my users to enter the temperature in Fahrenheit and get it returned in Centigrade, be able to enter miles per hour and get kilometers per hour and enter inches and get centimeters or enter yards and get meters.

This topic has been closed for replies.
Correct answer WolfShade

claudes59463176  wrote

I think I may have to use a database.

Uhm.. no.  Srsly.  No.

Assuming you follow my suggestion and use a select to allow the user to determine which conversion said user desires, the processing portion is simple math.

convert.cfm:

<cfparam name="response" default="0" />

<cfswitch expression="#form.conversion#">

     <cfcase value="f2c"><!--- Farenheit to Celsius --->

          <cfif val(form.thisValue) gt 0>

               <cfset response = (form.thisValue - 32) * 5/9 />

          </cfif>

     </cfcase>

     <cfcase value="c2f"><!--- Celsius to Farenheit --->

          <cfif val(form.thisValue) gt 0>

               <cfset response = form.thisValue * 9/5 +32 />

          </cfif>

     </cfcase>

     ...

</cfswitch>

Do the math for each conversion type and display #variables.response# on the processing page.  Voila.

HTH,

^ _ ^

1 reply

WolfShade
Legend
April 13, 2018

That's a pretty simple feat, yeah.  All you need are the calculations for the conversion.

I don't have time to sit and write it, for you, but anyone here can offer advice on your request.  But usually these forums are for helping you when something you've already written isn't working as expected.

Create your form, post the code here using Syntax Highlighting (use the advanced editor, highlight the code, then click on the >> at the top, choose Syntax Highlighting and select an option), and we can help with conditionals (if/else or switch/case) for which type of conversion, doing the math, etc.

V/r,

^ _ ^

UPDATE:  You could use a select to offer which type of conversion to let the user choose, fill it with options like:

F to C

C to F

mph to kmh

kmh to mph

in to cm

cm to in

yd to m

m to yd

claudes59463176
Participating Frequently
May 2, 2018

Thank you.  Still reading and learning, but haven't figured out how to change a result I get on the action page to a variable and process it further.  I think I may have to use a database.

WolfShade
WolfShadeCorrect answer
Legend
May 2, 2018

claudes59463176  wrote

I think I may have to use a database.

Uhm.. no.  Srsly.  No.

Assuming you follow my suggestion and use a select to allow the user to determine which conversion said user desires, the processing portion is simple math.

convert.cfm:

<cfparam name="response" default="0" />

<cfswitch expression="#form.conversion#">

     <cfcase value="f2c"><!--- Farenheit to Celsius --->

          <cfif val(form.thisValue) gt 0>

               <cfset response = (form.thisValue - 32) * 5/9 />

          </cfif>

     </cfcase>

     <cfcase value="c2f"><!--- Celsius to Farenheit --->

          <cfif val(form.thisValue) gt 0>

               <cfset response = form.thisValue * 9/5 +32 />

          </cfif>

     </cfcase>

     ...

</cfswitch>

Do the math for each conversion type and display #variables.response# on the processing page.  Voila.

HTH,

^ _ ^