HP Forums
Trouble with this programm. Please help! - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: Trouble with this programm. Please help! (/thread-3395.html)



Trouble with this programm. Please help! - Bea2306 - 03-16-2015 03:10 PM

Hi everybody I have had my hp prime for a few weeks now and I have trouble entering this program directly in the calculator. It says that there is a sintaxis problem. Can you help me fix it?Thank you.
This is the programm:
EXPORT PARAL(L1)
BEGIN
LOCAL T;
LOCAL I;
LOCAL N;
T:=0;
I:=0;
N:=SIZE(L1);

FOR I FROM 1 TO N DO
T:=T+1/L1(I);
END;

T:=1/T;
RETURN(T);
END;


RE: Trouble with this programm. Please help! - Marcio - 03-16-2015 03:48 PM

Try replacing 'SIZE' with 'length'.


RE: Trouble with this programm. Please help! - Bea2306 - 03-16-2015 04:00 PM

It says than the error is in line 4 and I don't understand why because I used the same sintaxis in line 3


RE: Trouble with this programm. Please help! - DrD - 03-16-2015 04:04 PM

The problem is the way you pass in the LIST (L1): Lists can't be used as inputs in the case.

Pre-define your list L1 then run this code:

Code:

EXPORT PARAL()  // Removed reference to L1
BEGIN
LOCAL T;
LOCAL I;
LOCAL N;
T:=0;
I:=0;
N:=SIZE(L1);

FOR I FROM 1 TO N DO
T:=T+1/L1(I);
END;

T:=1/T;
RETURN(T);
END;



RE: Trouble with this programm. Please help! - Marcio - 03-16-2015 04:09 PM

I would just replace SIZE with lenght as it will work with both lists and vectors.

Code:

EXPORT PARAL(L1)
BEGIN
LOCAL T;
LOCAL I;
LOCAL N;
T:=0;
I:=0;
N:=length(L1);

FOR I FROM 1 TO N DO
T:=T+1/L1(I);
END;

T:=1/T;
RETURN (T);
END;

Example:

Both PARAL([1 2 3]) and PARAL({1,2,3}) will return 6/11, which is equivalent to 0.545454....


RE: Trouble with this programm. Please help! - Bea2306 - 03-16-2015 04:16 PM

Now it says there is a problem with T:=0; Sad


RE: Trouble with this programm. Please help! - Didier Lachieze - 03-16-2015 04:32 PM

Are you sure you have the latest version of the Prime software?

With version 6975 I have no errors with your program.
Here is what I got:
[attachment=1810] [attachment=1811]

Regarding the variable names in your program I would recommend not to use Global names for local variables as this can be confusing. Having L1 as your program parameter doesn't change the content of the L1 global variable but this is confusing as well as using T, I and N for local variables. I would use lower case names instead of upper case to show the difference.