From b2ab7c3665c0a9eee6e8f208f1974253ce37eec9 Mon Sep 17 00:00:00 2001 From: gonzo Date: Sat, 10 Jun 2023 00:22:33 +0200 Subject: user may now select loan_type --- main.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index 992225c..5a73850 100644 --- a/main.c +++ b/main.c @@ -10,7 +10,7 @@ static WINDOW *pad; _Noreturn static void finish(int sig); void display_custom_form(FORM *); void print_contract(WINDOW *w, int x, int y, contract *c); -void run_sim(FORM *); +void run_sim(FORM *, char **contract_subtypes); int main() { int ch, i; @@ -29,7 +29,7 @@ int main() { FIELD *fields[8]; FORM *form; char *contract_types[] = { "loan", "savings", NULL }; - char *contract_subtypes[] = { "bullet", "sla", "mort", NULL }; + char *contract_subtypes[] = { "bullet", "sla", "mortgage", NULL }; /* initialize fields */ fields[0] = new_field(1, 11, 4, 22, 0, 0); /* contract type */ @@ -91,7 +91,7 @@ int main() { formactive = FALSE; curs_set(0); box(stdscr, 0, 0); - run_sim(form); + run_sim(form, contract_subtypes); padscroll = 0; refresh(); prefresh(pad, padscroll, 0, 4, 1, HEIGHT-2, WIDTH-1); @@ -159,12 +159,14 @@ void print_contract(WINDOW* w, int x, int y, contract *c) { (double)c->D, (double)c->A); } -void run_sim(FORM *form) { +void run_sim(FORM *form, char **contract_subtypes) { /* loan_type type; */ int n, d, yp; double r, p; + loan_type lt; FIELD **fields = form_fields(form); + lt = read_loan_type(contract_subtypes, field_buffer(fields[1], 0)); n = atoi(field_buffer(fields[2], 0)); yp = atoi(field_buffer(fields[3], 0)); d = atoi(field_buffer(fields[4], 0)); @@ -180,7 +182,7 @@ void run_sim(FORM *form) { /* setup pad */ pad = newpad(n+1, WIDTH-2); - mvwprintw(stdscr, 1, 2, "Reinbursement Table"); + mvwprintw(stdscr, 1, 2, "Reinbursement Table for %s", contract_subtypes[lt]); mvwprintw(stdscr, 3, 3, "%4s/%-4s | %12s | %10s | %10s | %10s\n", "cur", "tot", @@ -190,7 +192,8 @@ void run_sim(FORM *form) { "annuity"); /* run simulation */ - loan l = loan_init(MORTGAGE, n, d, r, p); + printf("%d\n", (int)lt); + loan l = loan_init(lt, n, d, r, p); for (int i = 0; i <= n; i++) { print_contract(pad, i, 2, l.c); loan_update(l); -- cgit v1.2.3