-
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);"> ° <STRONG>C</STRONG>
<STRONG>equals</STRONG>
<INPUT TYPE = "text"
NAME = "fahr"
VALUE = "32"
SIZE = "3"
MAXLENGTH = "3"
onChange = "cels.value =
Math.round(40 + this.value * 5.0/9.0 - 40);">
° <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
-
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
-
By jlopes151 in forum Database
Replies: 1
Last Post: 11-21-2005, 04:32 AM
-
Replies: 1
Last Post: 10-28-2005, 09:57 PM
-
Replies: 1
Last Post: 08-14-2005, 11:17 AM
-
By Gwen Smith in forum vb.announcements
Replies: 0
Last Post: 03-25-2003, 12:47 PM
-
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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks