From d01fc15a98e5ede02e3f9aff04e3d4014e6e484c Mon Sep 17 00:00:00 2001 From: gonzo Date: Fri, 19 May 2023 17:18:57 +0200 Subject: added delays to loans --- bullet_loan.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'bullet_loan.c') diff --git a/bullet_loan.c b/bullet_loan.c index 189ca05..2fc73d6 100644 --- a/bullet_loan.c +++ b/bullet_loan.c @@ -2,7 +2,7 @@ contract *bullet_init(int n, int d, float r, float P) { if ((n < 0)) return NULL; - if ((d > n)||(d < 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; @@ -15,13 +15,17 @@ contract *bullet_init(int n, int d, float r, float P) { float bullet_update(contract *c) { if (c->k > c->n) return 0.0f; + c->k++; c->I = c->r * c->P; + if (c->k == c->n) { c->D = c->P; c->P = 0.0f; } - c->A = c->D + c->I; + + if (c->k <= c->d) c->P += c->I; + else c->A = c->D + c->I; return c->A; } -- cgit v1.2.3