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

Simple program

Community Beginner ,
Apr 13, 2018 Apr 13, 2018

Copy link to clipboard

Copied

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.

Views

695

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

correct answers 1 Correct answer

LEGEND , May 02, 2018 May 02, 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 />

          <

...

Votes

Translate

Translate
LEGEND ,
Apr 13, 2018 Apr 13, 2018

Copy link to clipboard

Copied

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

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
Community Beginner ,
May 02, 2018 May 02, 2018

Copy link to clipboard

Copied

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.

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
LEGEND ,
May 02, 2018 May 02, 2018

Copy link to clipboard

Copied

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,

^ _ ^

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
LEGEND ,
May 02, 2018 May 02, 2018

Copy link to clipboard

Copied

Actually, now that I think about it.. you don't even need ColdFusion for this.  You could do it all in pure HTML and JavaScript.  Even set it so that once a conversion type is selected, the user enters a value in an input, then the conversion is calculated when the focus is removed from the input.

Just a thot.

^ _ ^

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
Community Beginner ,
May 02, 2018 May 02, 2018

Copy link to clipboard

Copied

Thank you, thank you, thank you. This is very helpful.  I wanted to do a whole conversion thing but my time is growing short so I am going try to use this as part of the bigger picture.  I just don't have the chops yet to do it all.  I scoured for weeks to find a solution that didn't involve a ton of work.  You have that.  It isn't a difficult task.  It takes logic and the time to sit down, think it through, plan it and just do it.  I think I may have been complicating it somewhat.  However, like I said I am new to CF and how to do things with it.  You are 100% correct.  This is easily done in HTML.  No need to bring the big guns in unless you are in a CF class and they want to see you do something next level up and that's what I was trying to do.  Back in the day (way back) in the days of Dinosaurs and BASIC, implement variables and arrays and looping and doing calculations was easy for me.  The concepts are basically the same but the terminology, syntax, order and process is different.  I did really well with some part of the course and not so well with the math part-- not because it is difficult, but they spend so little time on it.  It seems to me that the emphasis is on moving things around and drawing on the power of the omniscient, ever-present database.  Thanks so much for your help and I will see if I can do something with what you have provided.  Perhaps some day I will be able to help you out with something.  It most probably won't be programming-related, but maybe something else.  You never know.  But, I do know that things happen for a reason and we may cross paths again one day.  I sincerely appreciate your help.

Claude

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
LEGEND ,
May 02, 2018 May 02, 2018

Copy link to clipboard

Copied

Glad to be of assistance.  And, yeah, no point in using CF for something that can easily be done with JavaScript.  What I provided, you can just add to (copy/paste each case statement and alter as needed), so I hope this speeds things up, for you.

And I totally understand about "complicating it somewhat".  I've caught myself more than a few times applying a very complex solution to a very simple problem.  It's all about how one views things.  And when you are under a time crunch, it gets exponentially more difficult to see the 'easy path'.

But, welcome to CF, and I hope you enjoy it as much as I do.  There will always be someone here to answer questions or help troubleshoot code.

V/r,

^ _ ^

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
LEGEND ,
May 08, 2018 May 08, 2018

Copy link to clipboard

Copied

BTW.. once you have this finished, please post it here.  I created one, myself, and would like to compare notes.

V/r,

^ _ ^

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
LEGEND ,
Jun 19, 2018 Jun 19, 2018

Copy link to clipboard

Copied

(shrug)  In case Claude doesn't return, here's my idea (vanilla JavaScript - no jQuery):

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<style>*{margin: 0px; padding: 0px;}</style>
</head>

<body>
    <form>
        Enter a value, then choose what conversion type: <input type="text" id="thisValue" name="thisValue" />
        <select id="conversionType" name="conversionType">
        <option value="">Select</option>
        <option value="f2c">F to C</option>
        <option value="c2f">C to F</option>
        <option value="m2k">MPH to KPH</option>
        <option value="k2m">KPH to MPH</option>
        <option value="i2c">in to cm</option>
        <option value="c2i">cm to in</option>
        <option value="y2m">yd to m</option>
        <option value="m2y">m to yd</option>
        </select>
    </form>
    <div id="resultDiv"></div>

    <script type="text/javascript">
        var ct = document.getElementById('conversionType'),
            resultDiv = document.getElementById('resultDiv');
        function convertThis(){
            var thisValue = document.getElementById('thisValue').value,
                response;
            if((!isNaN(thisValue)) && (ct.value !== "")){
                switch(ct.value){
                    case "f2c":
                        response = (thisValue - 32) * 5 / 9 + " C";
                    break;
                    case "c2f":
                        response = thisValue * 9 / 5 + 32 + " F";
                    break;
                    case "m2k":
                        response = thisValue * 1.609344 + " kph";
                    break;
                    case "k2m":
                        response = thisValue / 1.609344 + " mph";
                    break;
                    case "i2c":
                        response = thisValue * 2.54 + " cm";
                    break;
                    case "c2i":
                        response = thisValue / 2.54 + " in";
                    break;
                    case "y2m":
                        response = thisValue / 1.0936 + " m";
                    break;
                    case "m2y":
                        response = thisValue * 1.0936 + " y";
                    break;
                    }
                resultDiv.innerHTML = response;
                }
            }
        ct.addEventListener('change',convertThis);

     </script>

</body>

</html>

This probably would have been better with a distributed table, but the switch/case is just fine.  Hope someone benefits from this. 

V/r,

^ _ ^

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
Community Beginner ,
Aug 10, 2018 Aug 10, 2018

Copy link to clipboard

Copied

Hello,

    I wanted to stop by and thank you and some of the other readers/developers out there that were willing to assist me on this.  Since I was new at the time (and still pretty new to the cold fusion programming side) my head was kind of spinning with all of the stuff that was being thrown at me at once.  I think I have a pretty good grip on what CF is about, what is can do, what we can do with it and start contributing back to the group, I have my own domain now where I am sharing some of the material I have learned and some of the things I am working on.  I'm not sure if this is the place to post but it's not hurting anything if I do.  I didn't do the conversion thing during last semester because some of the concepts were new to me and I couldn't quite get the output that I wanted so I borrowed just one (in the public domain) and used it for that project.  I still gave the author credit, because that's how I roll.  Do unto others, as I was taught growing up.  I'm still going to figure that out.  My restriction was that I learn ow to do it in Cold Fusion.  I see why people were saying it wasn't necessary and that it could be done in  a number of other ways.  That is true.  My Professor wanted to see me handle the form, the variables, the action page and the output and display it on a web page and I didn't have the chops to do it.  I have gotten much better and can do other things, but still having trouble finding the best way to do that and displaying the correct output or not more than one.  I will figure it out though.  I'm very close, especially with everyone's help.  It kind of doesn't make sense because I can do work like this: Pro2  This is  site I wrote almost, entirely in Cold Fusion using database-drive material.  It's not complete and has some typos, but as you can see, it works.  Beats me, why I can do the most impossible types of things, but put some legos in front of me and I probably couldn't stack 3 of them without the thing tipping over.

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
LEGEND ,
Aug 13, 2018 Aug 13, 2018

Copy link to clipboard

Copied

LATEST

Ah, I should have guessed that this was for a class.  You can still do it in CF, just seems ridiculous to do it in CF.  But if that's what the prof wants..

V/r,

^ _ ^

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
LEGEND ,
Jun 19, 2018 Jun 19, 2018

Copy link to clipboard

Copied

Hi, Claude,

Thank you for marking my answer as correct.  I do appreciate it.

V/r,

^ _ ^

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
Community Beginner ,
Jun 19, 2018 Jun 19, 2018

Copy link to clipboard

Copied

I am still around.  I appreciate the help.  As I stated earlier, I am new to CF and was seeking help to round out a project.  Some of this we simply hadn't covered.  I ended up doing a different project but still incorporated a few of the ideas posted into it, but I did go outside to another source because all I needed were weight conversions.  I simply could not justify or handle doing a project on solely on conversions when I didn't know how to complete the process at the time.  So I created something different that was better received for my skill level.  I just signed up for shared hosting and will be posting some of my work soon.

Took some time off to get away for a while and also deal with medical shtuff as I will be in July.  But, hopefully I'll get some time to sit down and get into writing some new material and posting up some of what I already did.  It's not Einsteinian by any stretch but I think I have some good ideas and wish to share with folks as well.  You will see that I am more the artist than the programmer, but I have been working to change that.  Next semester is going to be a doozie: Javacript, Advanced Web Development, PHP, and more Graphic Design stuff.  I was also able to fit in an accelerated Introduction to Java course during the spring so I have needed the time to decompress.  Now, I'm starting to get that itch again.

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