summaryrefslogtreecommitdiffstats
path: root/loans.c
blob: 46a51009b14c6de849d7e8c073b3e18820601c12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "loans.h"
#include "stdio.h"

loan loan_init(loan_type type, int n, int d, double r, double 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;
}

double 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;
	}
}