cancel
Showing results for 
Search instead for 
Did you mean: 
GRB43
Level 3
35 27 1 4
Message 1 of 3
604
Flag Post

Solved!

Help getting started with programing:

HP Recommended
HP-Prime
Linux

I was successful creating two user User Functions, "F2C" and "C2F".   "F2C" converts a Fahrenheittemperature to Celcius, and "C2F does the opposite.  I'm doing this as an exercise related to a response to one of my earlier posts as to how to save small formulas for easy recall.

For "F2C" I'm using the expression or formula:  CONVERT((F)_℉,1_℃   "F" is checked as a variable.  It works very nicely from the <Toolbox><User Functions> menu.  When you touch the Progam name, "F2C", the Input Bar displays "F2C(|)" with the cursor blinking in the middle of the parethesis.  Input a reasonable number such as "70" (F2C(70)), hit enter and 21.11__℃  is displayed.

I'm now trying to create a program that does the same thing.  I tried to copy a program from, eqnlib.hppgrm, from an HP website.   That program is as follows:

 

// 3 Temperature Conversion

if ch==3 THEN

"F9/5*C+32"%E1;

PRINT();

PRINT( "F = Temp. F" );

PRINT( "C = Temp. C" );

END;

 

I entered the following in my HP-Prime:

EXPORT Tst_Prg()

BEGIN

INPUT(F);

CONVERT((F)_℉,1_℃);

// EXPORT (1_℃);   -  without it being commented out it won't work at all

PRINT();

PRINT(1_℃)

PRINT( "F = Temp. F" );

PRINT( "C = Temp. C" );

END;

 

The program runs.  It stops and requests a value for F  You enter a value and  and prints out the quotes.

Somehow the value is not picked up by the formula or the program does not output the result of the formula.  In any case,   I don't know what I'm doing at all.  I did try to read the HP Guide Book.on the subject of progaming.

 

Any help or suggestions would be greatly appreciated.

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
cyrille
Level 6
Level 6
252 251 42 78
Message 2 of 3
Flag Post
HP Recommended

Hello,

Your program had a couple of problems...

Here is one that does work

EXPORT TstPrg()
BEGIN
LOCAL F; INPUT(F); // Create a local variable (F) and ask the user for a numerical value
LOCAL C= CONVERT((F)_°F,1_°C); // Convert that numerical value into a unit and convert it to celcius. Store in a new local variable
PRINT(); // print an empty line
PRINT( F+" = Temp. F" ); // print the input
PRINT( C+" = Temp. C" ); // print the output
RETURN C; // RETURN the output
END;

Cyrille

I am an HP Employee

View solution in original post

Was this reply helpful? Yes No
2 REPLIES 2
cyrille
Level 6
Level 6
252 251 42 78
Message 2 of 3
Flag Post
HP Recommended

Hello,

Your program had a couple of problems...

Here is one that does work

EXPORT TstPrg()
BEGIN
LOCAL F; INPUT(F); // Create a local variable (F) and ask the user for a numerical value
LOCAL C= CONVERT((F)_°F,1_°C); // Convert that numerical value into a unit and convert it to celcius. Store in a new local variable
PRINT(); // print an empty line
PRINT( F+" = Temp. F" ); // print the input
PRINT( C+" = Temp. C" ); // print the output
RETURN C; // RETURN the output
END;

Cyrille

I am an HP Employee

View solution in original post

Was this reply helpful? Yes No
GRB43
Author
Level 3
35 27 1 4
Message 3 of 3
Flag Post
HP Recommended

Thank you very much.  It's very satifying even though I was unable to do the work myself.  Do the variables stick for ever in the calculator or are they cleared after each run?  I tried to look for a CLEAR command, but there isn't one.

 

Also If I want to expand the program to convert Celcius to Fahrenheit is it possible to just add a few lines to this program, or is it better to make a seperate program that just reverses the process?

Was this reply helpful? Yes No
† The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation