diff options
| author | gonzo <gonzo@toniatuh.com> | 2023-06-10 14:36:57 +0200 |
|---|---|---|
| committer | gonzo <gonzo@toniatuh.com> | 2023-06-10 14:36:57 +0200 |
| commit | 83c81003c6ee96f542f59bc9f6815d15f00a1f10 (patch) | |
| tree | f79a284de090588b25e88e579b8b202ce9dd4385 | |
| parent | 990e1d65aac6a1c4ddd488ca232edc7ead8e06d9 (diff) | |
| download | loan_calc-83c81003c6ee96f542f59bc9f6815d15f00a1f10.tar.gz | |
added totals line
| -rw-r--r-- | main.c | 19 |
1 files changed, 16 insertions, 3 deletions
@@ -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; } |
