From 582542e39f1930c854c73d53744a8d4e369a7cf9 Mon Sep 17 00:00:00 2001 From: gonzo Date: Fri, 19 May 2023 10:31:51 +0200 Subject: initial commit, contract struct + bullet loan --- bullet_loan.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 bullet_loan.c (limited to 'bullet_loan.c') diff --git a/bullet_loan.c b/bullet_loan.c new file mode 100644 index 0000000..189ca05 --- /dev/null +++ b/bullet_loan.c @@ -0,0 +1,31 @@ +#include "loans.h" + +contract *bullet_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; + + return c; +} + +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; + + return c->A; +} + +void bullet_free(contract *c) { + free(c); +} -- cgit v1.2.3