Temperature conversion problem. Please help! - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: HP Prime (/forum-5.html) +--- Thread: Temperature conversion problem. Please help! (/thread-8807.html) |
Temperature conversion problem. Please help! - Skyblues - 08-10-2017 05:29 AM 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/thread-5018.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)) RE: Temperature conversion problem. Please help! - StephenG1CMZ - 08-10-2017 07:27 AM 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. RE: Temperature conversion problem. Please help! - Didier Lachieze - 08-10-2017 07:35 AM °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]); RE: Temperature conversion problem. Please help! - Skyblues - 08-12-2017 01:10 AM (08-10-2017 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 |