From 83c81003c6ee96f542f59bc9f6815d15f00a1f10 Mon Sep 17 00:00:00 2001 From: gonzo Date: Sat, 10 Jun 2023 14:36:57 +0200 Subject: added totals line --- main.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'main.c') 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; } -- cgit v1.2.3