Temperature Converter Problems


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Temperature Converter Problems

  1. #1
    Join Date
    Nov 2005
    Posts
    1

    Temperature Converter Problems

    Hi everyone,

    I'm sure that this will be a relatively simple questions for you experts, but I'm thoroughly confused trying to code this program. I have been assigned in school to create a temperature converter that converts celsius to farenheit and vice versa. I tried searching for code on the net, but none of the examples that I found use the same formula that I'm required to use. I must use the following formulae:
    F = (40 + C)*9/5 - 40 and
    C = (40 + F)*5/9 - 40

    This is the code that I'm trying to insert this formula into:
    ___________________________________________________________
    <INPUT TYPE = "text"
    NAME = "cels"
    VALUE = "0"
    SIZE = "3"
    MAXLENGTH = "3"
    onChange = "fahr.value =
    Math.round(40 + this.value * 9.0/5.0 - 40);"> &#176; <STRONG>C</STRONG>
    &nbsp; <STRONG>equals</STRONG> &nbsp;
    <INPUT TYPE = "text"
    NAME = "fahr"
    VALUE = "32"
    SIZE = "3"
    MAXLENGTH = "3"
    onChange = "cels.value =
    Math.round(40 + this.value * 5.0/9.0 - 40);">
    &#176; <STRONG>F</STRONG>*
    _____________________________________________________________

    The outputs are not correct, and I just can't figure out how to arrange this formula so that it works. Any help that you could give me would be greatly appreciated!

    Thanks,
    Matt

  2. #2
    Join Date
    Mar 2004
    Posts
    635
    Your problem here is order of operations. 40 has to be added to the degrees first, then that total is multiplied by the fraction. Use a parethesis as used in the equation example at the top.

    Math.round((40 + this.value) * 1.8 - 40)
    Math.round((40 + this.value) * (5/9) - 40)

Similar Threads

  1. Problems with MSSQLServer and Java
    By jlopes151 in forum Database
    Replies: 1
    Last Post: 11-21-2005, 04:32 AM
  2. Help with a method
    By NLS in forum Java
    Replies: 1
    Last Post: 10-28-2005, 09:57 PM
  3. Temperature Server
    By trixma in forum Java
    Replies: 1
    Last Post: 08-14-2005, 11:17 AM
  4. Replies: 0
    Last Post: 03-25-2003, 12:47 PM
  5. Replies: 0
    Last Post: 10-04-2000, 04:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center