summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgonzo <gonzo@toniatuh.com>2023-06-10 14:36:57 +0200
committergonzo <gonzo@toniatuh.com>2023-06-10 14:36:57 +0200
commit83c81003c6ee96f542f59bc9f6815d15f00a1f10 (patch)
treef79a284de090588b25e88e579b8b202ce9dd4385
parent990e1d65aac6a1c4ddd488ca232edc7ead8e06d9 (diff)
downloadloan_calc-83c81003c6ee96f542f59bc9f6815d15f00a1f10.tar.gz
added totals line
-rw-r--r--main.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/main.c b/main.c
index 40ecdcb..c7ca2cc 100644
--- a/main.c
+++ b/main.c
@@ -170,7 +170,7 @@ void display_custom_form(FORM *form) {
form_driver(form, REQ_FIRST_FIELD);
}
-void print_contract(WINDOW* w, int x, int y, contract *c) {
+void print_contract(WINDOW *w, int x, int y, contract *c) {
mvwprintw(w, x, y,
"%4d/%-4d | %12.2f | %10.2f | %10.2f | %10.2f\n",
c->k, c->n,
@@ -182,6 +182,7 @@ int run_sim(FORM *form, char **contract_subtypes) {
/* loan_type type; */
int n, d, yp;
double r, p;
+ double sumD, sumI, sumA;
loan_type lt;
FIELD **fields = form_fields(form);
@@ -201,16 +202,28 @@ int run_sim(FORM *form, char **contract_subtypes) {
r = r/(double)yp;
}
+ /* setup sums */
+ sumA = sumD = sumI = 0.0;
+
/* setup pad */
- pad = newpad(n+1, WIDTH-2);
+ pad = newpad(n+3, WIDTH-2);
/* run simulation */
loan l = loan_init(lt, n, d, r, p);
for (int i = 0; i <= n; i++) {
+ if (i) {
+ sumD += l.c->D;
+ sumI += l.c->I;
+ sumA += l.c->A;
+ }
print_contract(pad, i, 2, l.c);
loan_update(l);
}
- duration = n - HEIGHT + 6;
+
+ mvwprintw(pad, n+2, 2,
+ " Totals: | %10.2f | %10.2f | %10.2f\n",
+ sumI, sumD, sumA);
+ duration = n - HEIGHT + 8;
return 1;
}