03-16-2015, 03:10 PM
Post: #1
 Bea2306 Junior Member Posts: 5 Joined: Mar 2015
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;
03-16-2015, 03:48 PM
Post: #2
 Marcio Senior Member Posts: 438 Joined: Feb 2015
Try replacing 'SIZE' with 'length'.
03-16-2015, 04:00 PM
Post: #3
 Bea2306 Junior Member Posts: 5 Joined: Mar 2015
It says than the error is in line 4 and I don't understand why because I used the same sintaxis in line 3
03-16-2015, 04:04 PM
Post: #4
 DrD Senior Member Posts: 1,132 Joined: Feb 2014
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;
03-16-2015, 04:09 PM (This post was last modified: 03-16-2015 04:17 PM by Marcio.)
Post: #5
 Marcio Senior Member Posts: 438 Joined: Feb 2015
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....
03-16-2015, 04:16 PM
Post: #6
 Bea2306 Junior Member Posts: 5 Joined: Mar 2015
Now it says there is a problem with T:=0;
03-16-2015, 04:32 PM
Post: #7
 Didier Lachieze Senior Member Posts: 1,471 Joined: Dec 2013
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:

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.
 « Next Oldest | Next Newest »

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