我的目标是在返回true
false
或menu2/0
的程序
park(_,blue,basketball_court).
menu2 :-
nl,write('Select operation:'),nl,
write('1. Check which parking area available to park right now.'),nl,
write('2. Check whether a particular parking area is legal to park.'),nl,
write('3. End program.'),nl,
read(X),nl,choice(X).
choice(2):-
write('Enter your identity:'),nl,
read(C),
write('Enter sticker type:'),nl,
read(D),
write('Enter parking area:'),nl,
read(E),
park(C,D,E),
menu2.
以下是我得到的:
menu2.
Select operation:
1. Check which parking area available to park right now.
2. Check whether a particular parking area is legal to park.
3. End program.
2
Enter your identity:
staff
Enter sticker type:
blue
Enter parking area:
basketball_court
Select operation:
1. Check which parking area available to park right now.
2. Check whether a particular parking area is legal to park.
3. End program.
在basketball_court
之后,我希望True
出现。另外,在另一种情况下,即使出现'False',如何让它循环回menu2/0
?
答案 0 :(得分:1)
以下是如何做到这一点:
choice(2):-
write('Enter your identity:'),nl,
read(C),
write('Enter sticker type:'),nl,
read(D),
write('Enter parking area:'),nl,
read(E),
( park(C,D,E) ->
write('true'),nl
; write('false'),nl ),
menu2.