我在使用下面的代码时遇到问题。我尝试退出菜单时出错了。
park(_,blue,basketball_court).
time(officehour,_) :-
menu2.
go :- start_message,menu1.
start_message :-
write('This is a program'),nl.
menu1 :-
nl,write('Select operation:'),nl,
write('1. Input time'),nl,
write('2. Exit program'),nl,
read(Y), choice1(Y).
choice1(1):-
write('Place available to be parked:'),nl,
write('Input time:'),nl,
read(Y),
repeat,
time(Y,X),
write(X),nl,
fail,
menu1.
choice1(2):-
write('Exit program').
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.
choice(3):-
write('Exit program.').
以上是上述代码运行时的结果...正如您所看到的,我想看到的是Exit program. True
,而不是如下所示。
This is a program
Input time:
officehour
Place available to be parked:
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.
3
Exit program._896
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.
从这里忽略。我只是打字以满足发布.....
的要求