Post Reply 
Finance in Prime: odd period...
05-23-2015, 10:21 AM
Post: #7
RE: Finance in Prime: odd period...
Hi Salvo,

You sure have been burning the midnight candles on the finance programs! Your latest work has compiled without error and seems to run ok. I wanted to look through your coding to try to understand your approaches, so I took the liberty of adjusting the layout, in order for me to read through it better.

I was wondering if you would find it useful to control the number of digits in the user interface, (HDigits variable)?

When the result screens have been presented to the user, a helpful hint to let users know what to do next, might be useful. For example, "Press the Esc Key to continue..." or something.

It looks like you've figured out how to use INPUT() to your advantage. That function is not very well described in the help texts, as you might agree. It takes a little trial and error to get it working just the way a person might like!

Once a program accomplishes the basic goals, one can always tweak it for an enhanced user presentation / interface. Minimally, you've included textout_p() coding, which could also include color, and text size to help focus the user experience, for visual enhancement. The use of rectangular colored boxes for titles, and other interactions can aid visual interest. You might enjoy a little time off from the grind of getting the basic functions working, and have fun with the graphical user interface!

I hope these suggestions are useful.

-Dale-

Here's your program with formatting that makes it a bit easier for my eyes:

Code:

smenu();
diffDays();
numDays();
simpComp();

EXPORT odd_period()
BEGIN
smenu();
END;

diffDays()
BEGIN
  local day1, day2, n, fin, r;
  local dd1, dd2, mm1, mm2, yy1, yy2;
  local pv, beg, inte;
  local comp, pmt, anno,gg;

  input ({ {pv, [0], {15,15,1}}, 
           {n, [0], {40,15,1}},{r,[0],{70,15,1}},
           {beg,0, {15,2,2}}, {comp,0,{50,2,2}},
           {fin,0,{80,2, 2}},
           {dd1,[0],{15,15,4}}, 
           {mm1,{"1","2","3", "4", "5", "6", "7", "8", "9", "10", "11", "12"}, {40,15,4}}, 
           {yy1,[0],{70,15,4}},
           {dd2,[0],{15,15,5}}, 
           {mm2,{"1","2","3", "4", "5", "6", "7", "8", "9", "10", "11", "12"}, {40,15,5}}, 
           {yy2,[0],{70,15,5}} }, 
           "Calc payment with Î”days", 
           {"PV", "N","r%","End","Compound","Financial", "d1", "m1", "y1", "d2", "m2", "y2"}, 
           {"Present value (loan)", "Yearly pmt number", "APR Yearly rate%", "Begin or End", "Compound interest",
           "Financial year (360)", "Day 1", "Month 1", "Year 1", "Day 2", "Month 2", "Year 2"}, 
           {0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0,0}, 
           {1000, 36, 5, 1, 0, 1, 1, 1, 2015, 1, 1, 2015});

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

  IF (fin==0) THEN // Actual year
    gg:= DDAYS(day1, day2);
    anno:=365;
  ELSE // Financial year
    gg:= 30*(mm2-mm1)+dd2-dd1;
    anno:=360;
  END; //if

  inte:= simpComp(comp, pv, r, gg, anno);
  pmt:=Finance.CalcPMT(n, r, (-(pv+inte)),0,12,12,beg);
  RECT_P();
  TEXTOUT_P("Odd period " + EVAL(gg), 25,50);
  TEXTOUT_P("Interest odd period " + EVAL(inte), 25, 70);
  TEXTOUT_P("Monthly payment " + EVAL(pmt), 25, 90);
  WAIT;
  // RETURN pmt;
  smenu();
END;

numDays()
BEGIN
  local day1, day2, n, fin, r;
  local dd1, dd2, mm1, mm2, yy1, yy2;
  local pv, beg, inte;
  local comp, pmt, anno,gg;

  input ({ {pv, [0], {15,15,1}}, 
           {n, [0], {40,15,1}},{r,[0],{70,15,1}},
           {beg,0, {15,2,2}}, 
           {comp,0, {50,2,2}}, 
           {fin,0,{80,2, 2}},
           {gg, [0], {70,15,3}} }, 
           "Calc payment with num days", 
           {"PV", "N","r%","End","Compound","Financial","num Days"}, 
           {"Present value (loan)", "Yearly pmt number", "APR Yearly rate%", 
            "Begin or End", "Compound interest", "Financial year (360)", "Number of Days" }, 
           {0, 0, 0, 0, 0, 0, 0}, 
           {1000, 36, 5, 1, 0, 1, 20} );

        IF (fin==0) THEN // Actual year
          anno:=365;
        ELSE // Financial year
          anno:=360;
        END; //if

  inte:= simpComp(comp, pv, r, gg, anno);
  pmt:=Finance.CalcPMT(n, r, (-(pv+inte)),0,12,12,beg);
  RECT_P();
  TEXTOUT_P("Odd period " + EVAL(gg), 25,50);
  TEXTOUT_P("Interest odd period " + EVAL(inte), 25, 70);
  TEXTOUT_P("Monthly payment " + EVAL(pmt), 25, 90);
  WAIT;
  // RETURN pmt;
  smenu();
END;

simpComp(comp, pv, r, gg, anno)
BEGIN
  local inte;
  IF (comp==0) THEN // Simple interest
    inte:=(pv*(r/100)*(gg))/anno;
  ELSE // Compound interest
    inte:= pv*((r/100+1)^(gg/anno)-1);
  RETURN inte;
  END;
END;

smenu()
BEGIN
  local ch;
  CHOOSE(ch, "Odd Period", "Payment: difference Days", "Payment: number Days", "Quit");
  CASE
    IF ch==1 THEN diffDays(); END;
    IF ch==2 THEN numDays(); END;
    IF ch==3 THEN RETURN; END;
    DEFAULT
  END; // case
END;
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Finance in Prime: odd period... - salvomic - 05-21-2015, 10:40 AM
RE: Finance in Prime: odd period... - DrD - 05-23-2015 10:21 AM
RE: Finance in Prime: odd period... - DrD - 05-23-2015, 01:00 PM



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