Post Reply 
Simple Interest
05-17-2015, 07:48 PM (This post was last modified: 05-17-2015 09:51 PM by salvomic.)
Post: #3
RE: Simple Interest
this version works better:
changed type of input for days: no more checkbox, but textbox; added a function to calculate financial difference of dates (360 days/year): 30*(mm2-mm1)+dd2-dd1
It set Fixed 2 Digits format (almost a standard in Finance).

I need still a better control of error, as i.e. DDAYS gives error with non existent days (try DDAYS(2015.0201, 2015.0229) for example: 29 Feb doesn't exist, and the function gives error, so the program exit with "Error: Invalid input"...

Another thing a bit strange: if the order of input is:
dd1 (textbox), mm1 (checkbox), yy1 (textbox) ...
why the cursor goes from dd1 to yy1 and then to mm1 (in the same line)?

Code:

fin();
act();
calcd();
smenu();

EXPORT simple_interest()
BEGIN
// Set to Fixed 2 Mode
HFormat:=1;
HDigits:=2;
smenu();
END;

fin(n)
BEGIN
local mesg, r, pv, I;
input ({n,r, pv}, "Interest financial year", {"n","i", "PV"}, 
{"Period (day)", "rate%", "present value"},{n,0, 0} );
I:= (n/360)*pv*r/100;
mesg:= Eval(pv) +" for " + EVAL(n) + " days at " + EVAL(r) + "%" +
"
Interest (360 days) = " + EVAL(I) +
"
Total (PV + I) = " + EVAL(I+pv) + "";
PRINT;
PRINT (mesg);
WAIT (0);
smenu();
RETURN {I, I+pv, 360};
END;

act(n)
BEGIN
local mesg, r, pv, I;
input ({n,r, pv}, "Interest actual year", {"n","i", "PV"}, 
{"Period (day)", "rate%", "present value"},{n,0, 0} );
I:= (n/365)*pv*r/100;
mesg:= Eval(pv) +" for " + EVAL(n) + " days at " + EVAL(r) + "%" +
"
Interest (365 days) = " + EVAL(I) +
"
Total (PV + I) = " + EVAL(I+pv) + "";
PRINT;
PRINT (mesg);
WAIT (0);
smenu();
RETURN {I, I+pv, 365};
END;

calcd()
BEGIN
local mesg, days1, days2, n, flg;
local dd1, dd2, mm1, mm2, yy1, yy2;
HFormat:=0;
input ({ {dd1,[0],{15,15,1}}, 
{mm1,{"1","2","3", "4", "5", "6", "7", "8", "9", "10", "11", "12"}, {40,15,1}}, 
{yy1,[0],{70,20,1}},{dd2,[0],{15,15,3}}, 
{mm2,{"1","2","3", "4", "5", "6", "7", "8", "9", "10", "11", "12"}, {40,15,3}}, 
{yy2,[0],{70,20,3}},{flg,2,{85,2, 4}}
}, 
"Calc difference days", {"d1", "m1", "y1", "d2", "m2", "y2", "Financial"}, 
{"Day 1", "Month 1", "Year 1", "Day 2", "Month 2", "Year 2", "Financial year (360)"}, 
{1, 0, 0, 1, 0, 0, 0 }, {1, 0, 2015, 1, 0, 2015, 0} );

dd1:=EVAL(dd1); mm1:=EVAL(mm1);
dd2:=EVAL(dd2); mm2:=EVAL(mm2);
yy1:=EVAL(yy1); yy2:=EVAL(yy2);
days1 := yy1+mm1/100+dd1/10000;
days2 := yy2+mm2/100+dd2/10000;

if (flg==0) THEN
n:= DDAYS(days1, days2);
ELSE
n:= 30*(mm2-mm1)+dd2-dd1;
END; // if
mesg:="Days n = " + EVAL(n) +

from " + STRING(dd1) + "-" + STRING(mm1) + "-" + STRING(yy1) +
" to " + STRING(dd2) + "-" + STRING(mm2) + "-" + STRING(yy2) + 
"";
PRINT;
PRINT (mesg);
WAIT(0);
// Set to Fixed 2 Mode
HFormat:=1;
HDigits:=2;
IF (flg==1) THEN fin(n); ELSE act(n); END;

END;

smenu()
BEGIN
local ch;
CHOOSE(ch,"Simple Interest","n actual year","n finacial year", "Calc Date difference", "Quit");
CASE
IF ch==1 THEN act(0); END;
IF ch==2 THEN fin(0); END;
IF ch==3 THEN calcd(); END;
if ch==4 THEN return; END;
DEFAULT
END; //case
END;

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Simple Interest - salvomic - 05-17-2015, 03:10 PM
RE: Simple Interest - salvomic - 05-17-2015, 04:40 PM
RE: Simple Interest - salvomic - 05-17-2015 07:48 PM
RE: Simple Interest - salvomic - 05-18-2015, 01:59 PM



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