我是Prolog的新手,在修復第一個程序的錯誤時遇到了一些困難。Prolog Basic遞歸部門
程序要求是它使用遞歸分割2個輸入,如果分數大於除數,則返回0,忽略餘數。
%Author: Justin Taylor
testquotient :-
repeat,
var(Divident), var(Divisor), var(Answer), var(End),
write('Enter Divident: '),
read(Divident),
write('Enter Divisor: '),
read(Divisor),
quotient(Divident, Divisor, Answer),
nl,
write('Quotient is = '),
write(Answer),
nl,
write('Enter 0 to quit, 1 to continue: '),
read(End),
(End =:= 0),!.
quotient(_, 0, 'Undefined').
quotient(0, _, 0).
quotient(Divisor == Divident -> Answer = 1).
quotient(Divisor < Divident -> Answer = 0).
quotient(Divident, Divisor, Answer) :-
(Divisor > Divident -> Divisor = Divisor - Divident,
quotient(Divident, Divisor, Answer + 1);
Answer = Answer).
這功課嗎? – 2012-03-02 01:55:22
需要修復的錯誤是什麼? – 2012-03-02 20:51:34