forked from christianhujer/expensereport
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExpenseReport.pl
32 lines (25 loc) · 917 Bytes
/
ExpenseReport.pl
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
expense(Type, Amount, [Type, Amount]).
print_report([X|Y], Meals, Total) :-
expense(Type, Amount, X),
((Type = dinner; Type = breakfast) -> NMeals is Meals + Amount; NMeals is Meals),
(Type = dinner -> Name = 'Dinner';
Type = breakfast -> Name = 'Breakfast';
Type = car_rental -> Name = 'Car Rental'),
((Type = dinner, Amount > 5000; Type = breakfast, Amount > 1000) -> Marker = 'X'; Marker = ' '),
format('~a\t~a\t~a~n', [Name, Amount, Marker]),
NTotal is Total + Amount,
print_report(Y, NMeals, NTotal).
print_report([], Meals, Total) :-
format('Meal expenses: ~a~n', [Meals]),
format('Total expenses: ~a~n', [Total]).
print_report(X) :-
format('Expenses: ~a~n', ['']),
print_report(X, 0, 0).
main() :-
print_report([
[dinner, 5000],
[dinner, 5001],
[breakfast, 1000],
[breakfast, 1001],
[car_rental, 4]
]).