summaryrefslogtreecommitdiffstats
path: root/bullet_loan.c
diff options
context:
space:
mode:
authorgonzo <gonzo@toniatuh.com>2023-05-19 10:31:51 +0200
committergonzo <gonzo@toniatuh.com>2023-05-19 10:31:51 +0200
commit582542e39f1930c854c73d53744a8d4e369a7cf9 (patch)
treefd784c0b88d457605e536097c30c3fbbf0f3758f /bullet_loan.c
downloadloan_calc-582542e39f1930c854c73d53744a8d4e369a7cf9.tar.gz
initial commit, contract struct + bullet loan
Diffstat (limited to 'bullet_loan.c')
-rw-r--r--bullet_loan.c31
1 files changed, 31 insertions, 0 deletions
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);
+}