diff options
| author | gonzo <gonzo@toniatuh.com> | 2023-05-19 22:17:58 +0200 |
|---|---|---|
| committer | gonzo <gonzo@toniatuh.com> | 2023-05-19 22:17:58 +0200 |
| commit | 0751b55f611b889f63dfc2bc2705e7537703cb43 (patch) | |
| tree | 3a996ccde1904e92b910900d8d25c55424fff33d /loans.c | |
| parent | d01fc15a98e5ede02e3f9aff04e3d4014e6e484c (diff) | |
| download | loan_calc-0751b55f611b889f63dfc2bc2705e7537703cb43.tar.gz | |
added loan struct to abstract over loan types
Diffstat (limited to 'loans.c')
| -rw-r--r-- | loans.c | 48 |
1 files changed, 48 insertions, 0 deletions
@@ -0,0 +1,48 @@ +#include "loans.h" +#include "stdio.h" + +loan loan_init(loan_type type, int n, int d, float r, float P) { + loan ret; + ret.type = type; + + switch (type) { + case BULLET: + ret.c = bullet_init(n, d, r, P); + break; + case STRAIGHTLINE: + ret.c = sl_init(n, d, r, P); + break; + case MORTGAGE: + ret.c = mort_init(n, d, r, P); + break; + } + + return ret; +} + +float loan_update(loan l) { + switch (l.type) { + case BULLET: + return bullet_update(l.c); + case STRAIGHTLINE: + return sl_update(l.c); + case MORTGAGE: + return mort_update(l.c); + } + perror("Unkown Loan type supplied!"); + exit(EXIT_FAILURE); +} + +void loan_free(loan l) { + switch (l.type) { + case BULLET: + bullet_free(l.c); + break; + case STRAIGHTLINE: + sl_free(l.c); + break; + case MORTGAGE: + mort_free(l.c); + break; + } +} |
