Temperature conversion problem. Please help!

08102017, 05:29 AM
Post: #1




Temperature conversion problem. Please help!
Can one of you please help me figure out how to modify some code so I can do a temperature conversion?
I started this project by adding units to epp's excellent CNV program. I am using this as an educational exercise for myself. http://www.hpmuseum.org/forum/thread5018.html Everything is working except the temperature conversion. The problem is that if the first unit selected is Fahrenheit or Celsius, line 38 fails because those units contain a degree symbol ' ° ' ... So, at line 38, I have: x = 25 uFr = 1_°F (or 1_°C) x := x * uFr; (25 * 1_°F) which gives Error: Invalid input If I leave out the degree symbol, I am getting "Error: Inconsistent Units" which I believe is because the calculator uses the degree symbol for Fahrenheit or Celsius units internally. I have added the modified code below which only has the temperature conversion for review convenience. Thanks for the help! I am really trying to learn some basic Prime programming. Code: #pragma mode(separator(.,;) integer(h32)) 

08102017, 07:27 AM
(This post was last modified: 08102017 07:31 AM by StephenG1CMZ.)
Post: #2




RE: Temperature conversion problem. Please help!
If I recall correctly, there are two techniques that can be used to strip out units.
Mathematically, if one divides 3_m by 1_m the result is 3  a dimensionless number without any units. However, in the case of temperatures I am not certain that would work without first converting to Kelvin, because of the differing 0's. Alternatively, str(x) will yield a string like "3_m" and one can then strip out the underscore and unit from the string, leaving just "3". I have implemented temperature and other unit conversions In my Z_UNITS program. Stephen Lewkowicz (G1CMZ) It's the last week I have the freedom of Europe 

08102017, 07:35 AM
(This post was last modified: 08102017 07:36 AM by Didier Lachieze.)
Post: #3




RE: Temperature conversion problem. Please help!
°C and °F temperature units have some restrictrictions as explained here.
Your program works if I replace the lines 37 & 38: uFr := expr("1_" + unit[iPr,n]); x := x * uFr; by: x := expr(x + "_" + unit[iPr,n]); 

08122017, 01:10 AM
Post: #4




RE: Temperature conversion problem. Please help!
(08102017 07:35 AM)Didier Lachieze Wrote: °C and °F temperature units have some restrictrictions as explained here. Thanks for the ideas, I'm learning a lot here! I decided to go with Didier's solution. It's basically a string concationation to replace the need to multiply the units. Brilliant! Thanks, Jim 

« Next Oldest  Next Newest »

User(s) browsing this thread: 1 Guest(s)