2014-03-03 46 views
-1

目標: 在上面給出的代碼中應用一個循環,以便它會詢問「你想繼續嗎? (是/否)「,然後採取相應措施。 (提示:做一個謂詞'再次/ 0'做上面的任務)。我是序言新手,我被困在一個程序中

go:- 
    write('What is the name of Patient?'), 
    read(Patient),nl, 
    hypo(Patient, Disease), 
    write(Patient), 
    write(' probably has '), 
    write(Disease),nl. 

go:- 
    write('Sorry I am unable to diagnose the Disease.'),nl. 

hypo(Patient,flu):- 
    sym(Patient,fever), 
    sym(Patient,cough). 
hypo(Patient,headche):- 
    sym(Patient,bodypain). 
sym(Patient,fever):- 
    write(' Does '), 
    write(Patient), 
    write(' has fever (y/n)?'), 
    res(R), R='y'. 
sym(Patient,cough):- 
    write('Does '), 
    write(Patient), 
    write(' has cough (y/n)?'), 
    res(R), R='y'. 
sym(Patient,bodypain):- 
    write('Does '), 
    write(Patient), 
    write(' has bodypain (y/n)?'), 
    res(R), R='y'. 
res(R):- 
    read(R),nl. 
+0

你忘了提出一個問題。你要求我們做作業嗎? – CapelliC

+0

你可以這樣說。:| –

回答

0

您已經給出了一個帶有go謂詞的模型。訣竅是,如果R='y'沒有失敗,則通過遞歸地調用謂詞來獲得循環。

again :- 
    write('Do you want to continue? (Y/ N)'), 
    res(R), R='y', 
    go, 
    again. 
again :- 
    write('OK, bye'),nl. 
+0

謝謝。:)它的工作,但以這種方式。 再次: - 寫('你想繼續?(是/否)'), res(R),R ='y',再次, 。 –

相關問題