An inventory query
kfaraz_at_gmail.com
Date: 02/13/05
- Next message: Jan Burse: "Re: Writing functions for If-else statement in PROLOG"
- Previous message: sudha: "Writing functions for If-else statement in PROLOG"
- Next in thread: tmp123: "Re: An inventory query"
- Reply: tmp123: "Re: An inventory query"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 12 Feb 2005 23:51:27 -0800
hi
I've just started using prolog. I,ve started to make a model of a
retail system. I have defined the product nad the shopping cart(shown
below). One of the obvious queries is to find out the cost of each
product in the cart. The following code displays the cost correctly the
cost of each component of the cart, Now I would like to call
cost_of_cart(T,C), where T is the cart and C is the total cost of the
cart. for this how can I add the cost of the invidual products, in
order to obtain the total cost when the predicate cost_of_cart(T,C) is
called.
shopping_cart(cart1,[quant(12906,5),quant(7655,1), quant(4097,3)]).
cost_of_cart(T):-
shopping_cart(T,[quant(P,Y)|L]),
cost_of([quant(P,Y)|L]).
cost_of([]).
cost_of([quant(P,Y)|L]):-
product(P,D,_,_),
C is D * Y,
tab(4), write(P),put(9), write(C), nl,
cost_of(L).
the result of this program is
?- cost_of_cart(cart1).
12906 299.95
7655 489.99
4097 50.97
Yes
I am just startng of in prolog so any help in this regard will be
greatly appreciated.
- Next message: Jan Burse: "Re: Writing functions for If-else statement in PROLOG"
- Previous message: sudha: "Writing functions for If-else statement in PROLOG"
- Next in thread: tmp123: "Re: An inventory query"
- Reply: tmp123: "Re: An inventory query"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|