# 26.8: A.8- Programming the calculator

$$\newcommand{\vecs}{\overset { \rightharpoonup} {\mathbf{#1}} }$$ $$\newcommand{\vecd}{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}}$$$$\newcommand{\id}{\mathrm{id}}$$ $$\newcommand{\Span}{\mathrm{span}}$$ $$\newcommand{\kernel}{\mathrm{null}\,}$$ $$\newcommand{\range}{\mathrm{range}\,}$$ $$\newcommand{\RealPart}{\mathrm{Re}}$$ $$\newcommand{\ImaginaryPart}{\mathrm{Im}}$$ $$\newcommand{\Argument}{\mathrm{Arg}}$$ $$\newcommand{\norm}{\| #1 \|}$$ $$\newcommand{\inner}{\langle #1, #2 \rangle}$$ $$\newcommand{\Span}{\mathrm{span}}$$ $$\newcommand{\id}{\mathrm{id}}$$ $$\newcommand{\Span}{\mathrm{span}}$$ $$\newcommand{\kernel}{\mathrm{null}\,}$$ $$\newcommand{\range}{\mathrm{range}\,}$$ $$\newcommand{\RealPart}{\mathrm{Re}}$$ $$\newcommand{\ImaginaryPart}{\mathrm{Im}}$$ $$\newcommand{\Argument}{\mathrm{Arg}}$$ $$\newcommand{\norm}{\| #1 \|}$$ $$\newcommand{\inner}{\langle #1, #2 \rangle}$$ $$\newcommand{\Span}{\mathrm{span}}$$$$\newcommand{\AA}{\unicode[.8,0]{x212B}}$$

This section is more advanced and is only recommended for students who are familiar with programming languages.

## Hello world

A ‘Hello World’ program is a program that only displays the words “Hello World.” It is a starting point to understand the procedure of creating and running a program before going to more advanced programming techniques.

To create a new program press $$\boxed{\text{prgm}}$$, move to the right $$\boxed{\triangleright}$$ to ‘NEW,’ and give it the name ‘HELLO.’ Next, we need to add the Display command. Press $$\boxed{\text{prgm}}$$; you see a list of commands. We move to the right to ‘I/O’ for input/output commands. Select the third item ‘Disp’ for display. To finish, we need to add ‘"HELLO WORLD."’ (Quotation marks obtained by pressing $$\boxed{\text{alpha}}$$$$\boxed{\text{+}}$$; space is obtained by $$\boxed{\text{alpha}}$$$$\boxed{\text{0}}$$.) The complete program is shown below. To execute the program, quit $$\boxed{\text{2nd}}$$$$\boxed{\text{mode}}$$, press $$\boxed{\text{prgm}}$$ and confirm with $$\boxed{\text{enter}}$$. After another $$\boxed{\text{enter}}$$, the program should run as shown below. We next implement the quadratic formula

$ax^2+bx+c=0 \quad\implies \quad x=\dfrac{-b\pm\sqrt{b^2-4ac}}{2a} \nonumber$

Create a new program ‘QUADRATI.’ We now need a new command, the Prompt command which will ask for three input values and places them in the variables A, B, C. The Prompt command is the second item in the ‘I/O’ menu. After executing the new program, enter any input values (for example A$$=3$$, B$$=-10$$, C$$=-8$$). The answer should appear below. ## Directional angle

Our third and last program calculates the directional angle of a vector $$\vec{v}=\langle a,b\rangle$$. Recall that the angle is $$\tan^{-1}(b/a)$$ or $$\tan^{-1}(b/a)+180^\circ$$ depending on the quadrant in which $$\vec{v}$$ is pointing. In quadrant II and III, we need to add $$180^\circ$$ degrees. This is exactly the case when $$a<0$$. Thus, we prompt for input values A and B, and we calculate $$\tan^{-1}(b/a)$$ and place it into the new variable G. (The arrow is obtained by pressing $$\boxed{\text{sto}}$$.) We then check if $$a<0$$, in which case we add $$180$$ to G. (Here, we are assuming that the calculator is in degree mode). Note that the ‘If’ command is obtained by pressing $$\boxed{\text{prgm}}$$, and ‘$$<$$’ is obtained from the TEST menu, press $$\boxed{\text{2nd}}$$$$\boxed{\text{math}}$$and then $$\boxed{\text{5}}$$. We may now run the program and check its correctness in some examples. ## Other projects

Here is a list of projects that you may want to try to implement on your calculator.

1. Display the final amount of an investment for a given principal $$P$$, annual interest rate $$r$$, number of compoundings per year $$n$$, and number of years $$t$$ (see Observation [OBS:n-th-compounding] on page ).
2. In the program above for the directional angle, check for the cases when $$a=0$$, and display the correct answers.
3. Implement the long division (see Chapter 8).

## Erasing a program

To erase a program that you have written, press $$\boxed{\text{2nd}}$$$$\boxed{\text{+}}$$, then $$\boxed{\text{2}}$$, then $$\boxed{\text{1}}$$. A list of all your programs appears. Select the program you want to delete with $$\boxed{\triangle}$$$$\boxed{\triangledown}$$ and press the $$\boxed{\text{del}}$$ key. Confirm your selection with $$\boxed{\text{2}}$$ ‘Yes.’ This page titled 26.8: A.8- Programming the calculator is shared under a CC BY-NC-SA 4.0 license and was authored, remixed, and/or curated by Thomas Tradler and Holly Carley (New York City College of Technology at CUNY Academic Works) via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.