We will present two programs that make use of calling subroutines indirectly.

Random Voting Machine

This program uses the calculator's random function to count a specified number of votes between two candidates: Candidate 0 and Candidate 1. In order to get the calculator to round the random number to 0 or 1, we use the setting Fix 0, then execute the RND (round) function.

RND rounds the displayed number, using the display settings for the number of decimal points used.

Labels used: A (main), 0, 1, 2 (loop)

Storage Registers Used:R0 = number of votes Candidate 0 receivesR1 = number of votes Candidate 1 receivesR2 = total number of votes

Instructions:1. Enter the number of votes to be counted.2. Press [ f ] [ √ ] (A)3. The number of votes for Candidate 0 is displayed. Press [R/S] to display the number of votes for Candidate 1.

Example:A sample vote of 25 votes: 25 [ f ] [ √ ] (A)

You may get 13 votes for Candidate 0 and 12 votes for Candidate 1.

A sample vote of 2,500 votes yields 1,252 votes for Candidate 0 and 1,248 votes for Candidate 1. It took about 17 seconds for the program to run on the HP 15C Limited Edition. It may take considerably longer on the original HP 15C.

Fresnel Integrals

This program calculates the Fresnel Integrals:

Fresnel Sine Integral: S(x) = √(2/π) × ∫((sin u)^2, u, 0, x)

Fresnel Cosine Integral: C(x) = √(2/π) × ∫((cos u)^2, u, 0, x)

This program sets an index. If RI = 0, S(x) is calculated. If RI = 1, C(x) calculated. If RI > 1, the program flashes to communicate an error condition. RI is set before program execution.