Post Reply 
Dealing with Integers on the Prime. (SOLVED!)
04-13-2015, 05:23 AM (This post was last modified: 04-14-2015 10:18 PM by Spybot.)
Post: #1
Dealing with Integers on the Prime. (SOLVED!)
Hi Everyone!

My question is... How do I control a program to accept only positive integers as input arguments? (I hope it is possible!).
The following code accepts pretty much anything(integers,fraction, floating etc...). So, looking for more information about types of objects in the Prime, we all know the TYPE command, which says that [0] are reals, and [1] are integers. So that's how I assume they are consolidated internally, Am I wrong?

EXPORT test1()
BEGIN
LOCAL var;
INPUT(var,[1],"Title","Label","Enter an Integer.");
MSGBOX(var);
END;

Why it is accepting any kind of input?


Thank you.

   

Spybot.

Spybot.
Find all posts by this user
Quote this message in a reply
04-13-2015, 09:26 PM (This post was last modified: 04-13-2015 10:56 PM by Spybot.)
Post: #2
RE: Dealing with Integers on the Prime. Help!
Here's another attemp... and it still doesn't work! it accepts any kind of numbers.


EXPORT test1()
BEGIN
LOCAL var;
INPUT({{var,[DOM_INT]}},"title","value:","help");
PRINT();
PRINT(var);
END;

What makes me wonder... ! What is an integer for the HP Prime Calculator? I tried RANDINT(1,1,3) and I got: [2](this is supposed to be an integer), then I first tried with the TYPE command to see if this was an integer, so: TYPE([2]) returns: 6 as a result, and 6 is the type of object for lists, so I took the 2 out of the list: [2](1), and I got: 2.<-(notice the decimal point) then I used TYPE again: TYPE(2.) and it returns: 0, which corresponds for reals.

So I keep asking myself... Do integers really exist on the HP Prime? if so, I'd like to meet them. and see how they look like.

Spybot.

Spybot.
Find all posts by this user
Quote this message in a reply
04-13-2015, 10:12 PM
Post: #3
RE: Dealing with Integers on the Prime. Help!
#<num>:<bits><base>

#1h, #3:23h, etc

Integers in home are the fixed range, hex/oct/bin/dec objects. These are not the same integers as in the CAS system.

TW

Although I work for HP, the views and opinions I post here are my own.
Find all posts by this user
Quote this message in a reply
04-13-2015, 10:35 PM
Post: #4
RE: Dealing with Integers on the Prime. Help!
Hello Tim!

Thank for the feed back.

So, those are the real Integers (pretty scary though), that's why I wasn't able to input them.

So... Is it possible for a regular program in the Prime to accept only regular integers(1,2,3,4...) as input and at the same time to accept only positive ones, while using the INPUT command?

Thank you.

Spybot.

Spybot.
Find all posts by this user
Quote this message in a reply
04-14-2015, 12:23 AM
Post: #5
RE: Dealing with Integers on the Prime. Help!
(04-13-2015 10:35 PM)Spybot Wrote:  Hello Tim!

Thank for the feed back.

So, those are the real Integers (pretty scary though), that's why I wasn't able to input them.

So... Is it possible for a regular program in the Prime to accept only regular integers(1,2,3,4...) as input and at the same time to accept only positive ones, while using the INPUT command?

Thank you.

Spybot.

You can create a loop that contains the input command. Have your loop then process the result from the input command. Let's say you store the value entered in the variable intvar. The loop repeats so long as FP(intvar)<>0. FP() denotes the fractional part, and is an actual command.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
04-14-2015, 03:11 AM (This post was last modified: 04-15-2015 01:49 AM by Spybot.)
Post: #6
RE: Dealing with Integers on the Prime. Help!
Hello Han!

Thank you for responding.

Your suggestion looks very interesting, I thought the INPUT command had some obscure parameters that may be useful to me and my needs, but I see the INPUT command doesn't control that kind of parameters at the moment.

So, I'll give it a try your way, I'll report soon.


Spybot.

Spybot.
Find all posts by this user
Quote this message in a reply
04-14-2015, 11:18 AM
Post: #7
RE: Dealing with Integers on the Prime. Help!
Here's a skeleton for your closet:

EXPORT Intgr()
BEGIN
local Zi;

repeat
Zi:=0; // Recycles non-integers
input(Zi);
until fp(Zi)==0;

return Zi;

END;
Find all posts by this user
Quote this message in a reply
04-14-2015, 05:43 PM
Post: #8
RE: Dealing with Integers on the Prime. Help!
Hi DrD!

Thank for your suggestion,

I have a question, the program accepts the input values perfectly, just the way I wanted, but when I'm entering the values the program just don't exit, even if I press ESC or back-Space(DEL), it forces the User to enter the correct type of arguments otherwise the program won't end. how can I exit the program anytime I want?




EXPORT test()
BEGIN
local A,B,C;
repeat {A:=0,B:=0,C:=0}; // Recycles non-ntegers
INPUT({{A,[0],{10,15,1}},{B,[0],{40,15,1}},{C,[0],{70,15,1}}},"STANDARD FORM",{"A:","B:","C:"},{"Coefficient A must be a Positive Integer.","Coefficient B must be an Integer.","Coefficient B must be an Integer."});
until fp(A)==0 AND A≥0 AND fp(B)==0 AND fp(C)==0;
PRINT();
PRINT("Values are Valid.");
PRINT("A="+A+" B="+B+" C="+C);
END;

Spybot.

Spybot.
Find all posts by this user
Quote this message in a reply
04-14-2015, 06:14 PM
Post: #9
RE: Dealing with Integers on the Prime. Help!
The input command itself will return a 1 if the user pressed [Enter] or selected the "OK" menu option. Otherwise, it returns a 0. If the result is 0, then you can use BREAK to exit the loop or KILL to completely exit the program.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
04-14-2015, 09:28 PM (This post was last modified: 04-14-2015 09:31 PM by DrD.)
Post: #10
RE: Dealing with Integers on the Prime. Help!
(04-14-2015 05:43 PM)Spybot Wrote:  >>> how can I exit the program anytime I want?
Spybot.

You can always exit the program by using the "On" key. If you want to exit the repeat loop, insert a test condition, (example in bold), after the input statement:

EXPORT test()
BEGIN
local A,B,C;

repeat
{A:=0,B:=0,C:=0}; // Recycles non-integers
INPUT({{A,[0],{10,15,1}},{B,[0],{40,15,1}},{C,[0],{70,15,1}}},"STANDARD FORM",{"A:","B:","C:"},{"Coefficient A must be a Positive Integer.","Coefficient B must be an Integer.","Coefficient B must be an Integer."});
If (A==B)==C==0 then return "Done"; end; // No inputs changed, just "Enter" at input prompt
until fp(A)==0 AND A≥0 AND fp(B)==0 AND fp(C)==0;

PRINT();
PRINT("Values are Valid.");
PRINT("A="+A+" B="+B+" C="+C);
END;
Find all posts by this user
Quote this message in a reply
04-14-2015, 10:17 PM (This post was last modified: 04-15-2015 01:51 AM by Spybot.)
Post: #11
RE: Dealing with Integers on the Prime. Help!
I feel Blessed!

Great help I've been getting today.

Thank you DrD and Han your help! It was very illustrative to me. I wasn't aware of the 1 and 0 that the INPUT command returns everytime it is executed, but from now on I will be.
Well I finally got this thing going the way I wanted.



EXPORT test()
BEGIN
LOCAL A,B,C;
REPEAT
{A:=0,B:=0,C:=0};
INPUT({{A,[0],{10,15,1}},{B,[0],{40,15,1}},{C,[0],{70,15,1}}},"STANDARD FORM",{"A:","B:","C:"},{"Coefficient A must be a Positive Integer.","Coefficient B must be an Integer.","Coefficient B must be an Integer."});
UNTIL fp(A)==0 AND A≥0 AND fp(B)==0 AND fp(C)==0;
IF 0 THEN BREAK;
END;
END;



Thank you Guys!


Spybot.

Spybot.
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)