From ad2a003a77dc234a6eb5628b298630d54b337604 Mon Sep 17 00:00:00 2001 From: gonzo Date: Fri, 19 May 2023 10:44:54 +0200 Subject: added straight-line loans --- straight_line_loan.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 straight_line_loan.c (limited to 'straight_line_loan.c') diff --git a/straight_line_loan.c b/straight_line_loan.c new file mode 100644 index 0000000..0d25247 --- /dev/null +++ b/straight_line_loan.c @@ -0,0 +1,29 @@ +#include "loans.h" + +contract *sl_init(int n, int d, float r, float P) { + if ((n < 0)) return NULL; + if ((d > n)||(d < 0)) return NULL; + contract *c = (contract *)calloc(1, sizeof(contract)); + c->n = (unsigned int)n; + c->d = (unsigned int)d; + c->r = r; + c->P = P; + c->D = P/(float)n; + + return c; +} + +float sl_update(contract *c) { + if (c->k > c->n) + return 0.0f; + c->k++; + c->I = c->r * c->P; + c->P = c->P - c->D; + c->A = c->D + c->I; + + return c->A; +} + +void sl_free(contract *c) { + free(c); +} -- cgit v1.2.3