-1

我正在使用 SWI prolog 要求用户根据以下代码插入两个不同的值:

base:-
   write('\n Please enter the base and exponent or 0 and 0 to stop the program:'),
   read   (X),
   read(Y),
   bas(X,Y).

bas(0,0):- !.
bas(X,Y):-
   f is X*Y,
   write('The power of '),write(x),
   write(' raised to '),write(y),
   write(' is '),write(f),
   base.

但是在我进行咨询之后,第一行将显示(插入数字)但是当我插入它为我显示的值时出现错误。那么错误是什么以及为什么程序无法读取我的不同值

4

1 回答 1

0

here a slight reformulation

base :-
    writeln('enter base and exponent (terminate with .) or 0 and 0 to stop the program'),
    read(X),
    read(Y),
    bas(X,Y).

bas(0,0):- !.
bas(X,Y):-
    P is X ^ Y,
    format('The power of ~w raised to ~w is ~w~n', [X,Y,P]),
    base.

to me, such interaction seems a bit weird:

?- base.
enter base and exponent (terminate with .) or 0 and 0 to stop the program
|: 4.
|: 2.
The power of 4 raised to 2 is 16
enter base and exponent (terminate with .) or 0 and 0 to stop the program
|: 0.
|: 0.
true.
于 2013-03-17T21:51:44.483 回答