HP Prime Programming Tutorial: Displaying Results

by DemolisionWolf in Circuits > Computers

8058 Views, 3 Favorites, 0 Comments

HP Prime Programming Tutorial: Displaying Results

exAllresults.jpg

This instruction isn't intended to be a primary location of learning to program the HP Prime. These are a few things I've spent hours learning and just want to share so another novice programmer can get up and running faster. The 600+ page manual offered by HP does a good job clarifying syntax and how to get started in programming.

For now, I'm just covering how to display program results.

Displaying Results

exAllresults.jpg

Depending on what you want to display, there are several options.

  • Display a single number (47)
  • Display a single number and text (A=47)
  • Display multiple numbers (47, 13)
  • Display multiple numbers and text (A=47 and B=13)

And another influence is do you want to do more calculations with them?

Once you add text to your program results, you are no longer allowed to do calculations. I prefer not using text because I can't do further calculations with the result (unless I type it on the home screen myself).

When trying to display two or more numbers in a result and still do calculations, I use a matrix or a list.

Here are various syntax examples, (let A and B represent program variables and A=47 and B = 13)

​Displaying: Example 1

ex1code.jpg

RETURN A;

// This will return a value to the home screen, which can be used in future calculations

Displaying: Example 2

ex2code.jpg
exAllresults.jpg


RETURN "The answer is "+A;

// this returns a string, no further calculations can be done with result, only viewing.

Displaying: Example 3

ex3code.jpg
exAllresults.jpg

RETURN "A value is " + A + " B value is" + B;

// displays a string, only viewing is allowed, no further calculations can be done.

Displaying: Example 4

ex4code.jpg
ex4matrix.jpg
exAllresults.jpg

M1(1) refers to matrix one and the first element in the matrix.

M1(2) refers to matrix one and the second element in the matrix.

RETURN M1;

Matrixs allow the display of multiple numbers from a program's results as well as allowing you to do further as seen in the pic.

In order to use a matrix, you must go to the matrix list on the HP Prime, and select M1(our matrix of choice), then choose it to be a vector.
For more information on Matrixs, refer to the HP User Guide

Displaying: Example 5

ex5code.jpg
exAllresults.jpg

L1(1) refers to List 1 and it's first element.

L1(2) refers to List 1 and it's second element.

RETURN L1;

Lists allow the display of multiple numbers from a program's results as well as allowing you to do further as seen in the pic.

For more information on Lists, refer to the HP User Guide

Displaying Numbers in Decimal Form

To get you program to return decimal values, use

RETURN approx(A);

the approx will approximate the variable A giving you a decimal answer.

Or, you can run the program from the CAS home, then press the button left of the delete button.