** HP Prime: The Percent Function**

**The Percent Function**

The HP Prime has three percent functions. They are not easily found (through the catalog or in program edit mode, Cmds-More menu). The functions are:

%

%CHANGE

%TOTAL

% Function

%(x, y) returns x * y /100. This returns either x% of y or y% of x. Due to the communicative multiplication property, you can use the arguments in either order.

%CHANGE

This the percent change function where the arguments are %CHANGE(old, new). Formula: %CHANGE(x, y) = (y - x) / x * 100%

%TOTAL

This calculates the % total given a part and a whole. Syntax: %TOTAL(whole, part). Formula: %TOTAL(x, y) = y / x * 100%

The program POPTOWN uses the percent functions. It is a simple game where you invite a certain population to live in a town, and the birth (growth) and death rates are determined by random.

**HP Prime Prime Program: POPTOWN**

RESULTS(y,n,g,d,p)

BEGIN

// subroutine

PRINT();

PRINT("Year: "+STRING(y));

PRINT("Population: "+STRING(n));

IF y>0 THEN

PRINT("Growth: "+STRING(g)+"%");

PRINT("Death: "+STRING(d)+"%");

PRINT("Δ%: "+%CHANGE(p,n));

END;

WAIT(0);

END;

// main program

EXPORT POPTOWN()

BEGIN

MSGBOX("You start with 10

residents, inviting up to 50

new residents each year. Can

growth beat death?");

// 2020-10-24 EWS

// Growth and Death

LOCAL n,y,w,g,d,c,p;

LOCAL v; // number of invites

n:=10;

RESULTS(y,n,g,d,p);

// The game

FOR y FROM 1 TO 5 DO

INPUT({{c,{0,10,20,30,40,50}}},

"Year "+STRING(y),"Invite:");

// all invites move in at the

// beginning of each turn

p:=n;

w:=10*(c-1)+n;

v:=10*(c-1)+v;

g:=RANDINT(5,20);

d:=RANDINT(1,25);

n:=w+IP(%(w,g))-IP(%(w,d));

// empty town scenario

IF n≤0 THEN

MSGBOX("No one survived.");

n:=0;

END;

RESULTS(y,n,g,d,p);

END;

// End the game results

PRINT("Final Results");

PRINT("Population Change: "+

STRING(n-10));

PRINT("Invited: "+STRING(v));

PRINT("Percent Invite: "+

STRING(ROUND(%TOTAL(n,v),2))

+"%");

END;

Eddie

All original content copyright, © 2011-2020. Edward Shore. Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited. This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.

This comment has been removed by the author.

ReplyDeleteExcuse me, I wrote again below. Thank you

DeleteHi Eddie, is it worth buying an HP Prime G2 in 2020 ?. I have an HP Prime G1, Hardware version A, and I have thought about buying the G2 because I am bothered by the poorly readable keys, in addition to the problem of screen flickering and low RAM in the G1. But I don't know if the new model is worth buying in the middle of 2020. I have read that some have reboot problems, or key problems. But I don't know how true this is. I don't see HP working on new firmware for months, nor do I see HP promoting their calculator. I suppose it's because of the pandemic, but this worries me. This also makes me doubt whether to buy it. Could you help me decide. Sorry for my bad English, my native language is Spanish. Thank you

ReplyDelete

ReplyDeleteEVO Club

SA Casino