Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Prolog quiz

Status
Not open for further replies.

0741044035

Technical User
Apr 29, 2012
1
RO
I created a small program for finding out which is the risk to have cardiovascular diseases.
The problem is when I type something different than y(yes).. it doesn't always stop and keeps asking me the same questions. How can I make it stop and accept all kinds of answers?
Thanks a lot!

predicates
risk(symbol)
age(symbol)
smoke(symbol)
diabet(symbol)
obesity(symbol)
rel(symbol,symbol)
infl_age(integer)
infl_smoke(integer)
infl_diabet(integer)
infl_obesity(integer)

clauses


risk(extreme) if infl_age(A),infl_smoke(B),infl_diabet(C),infl_obesity(D), A+B+C+D>90.
risk(big) if infl_age(A),infl_smoke(B),infl_diabet(C),infl_obesity(D), A+B+C+D>70.
risk(medium) if infl_age(A),infl_smoke(B),infl_diabet(C),infl_obesity(D), A+B+C+D>40.
risk(low) if infl_age(A),infl_smoke(B),infl_diabet(C),infl_obesity(D), A+B+C+D>20.
risk(safe) if !.

age(X) if rel(age,X).
smoke(X) if rel(smoke,X).
diabet(X) if rel(diabet,X).
obesity(X) if rel(obesity,X).
rel(Atribut,Valoare) if write(Atribut,":",Valoare,"?"), readln(R), R="y".


infl_age(20) if age(over_50),!.
infl_age(10) if age(between_30_and_50),!.
infl_age(0) if !.

infl_smoke(30) if smoke(do_you_smoke),!.
infl_smoke(0) if !.

infl_diabet(25) if diabet(are_you_diabetic),!.
infl_diabet(0)if !.

infl_obesity(25) if obesity(are_you_a_fat_person),!.
infl_obesity(0) if !.

goal

risk(X),
write("the risk for having cardiovascular ilnesses is:",X).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top