2013-03-17 81 views
-1

林與SWI序言工作,要求用戶按照下面的代碼插入兩個不同的值,從用戶那裏獲取兩個值:如何通過使用SWI序言

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. 

但之後我做的諮詢第一行會顯示(插入數字),但是當我插入它顯示的值時出錯。 那麼,什麼是錯誤,爲什麼程序不能讀我的不同的價值觀

+0

大寫/低案件麻煩也許?你不能隨意更改大小寫,它們有意義。 – 2013-03-17 20:57:50

+0

我做了,但是這個錯誤顯示給我錯誤:流user_input:67:71語法錯誤:操作符預期 – user2090366 2013-03-17 21:16:20

+0

在這裏你不能有空格'read(X)' – CapelliC 2013-03-17 21:52:32

回答

0

這裏稍微再形成

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. 

對我來說,這種互動似乎有點不可思議:

?- 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.