There are many possible ways to store values. What you probably think of - storing some counters and updating them on given answers - can lead to some complicated situations. Example of code working with counters:
question('Choose a, b or c: ').
question('Choose again a, b or c: ').
question('Think before you choose a, b, or c: ').
ask :-
findall(Q, question(Q), Questions),
ask_and_count([0,0,0], [A,B,C], Questions),
max_list([A,B,C], Max),
nth1(Index,[A,B,C],Max),
nth1(Index,[a,b,c],Answer),
print('You''re a(n) '), print(Answer), nl.
ask_and_count(Count, Count, []) :-
print('Thank you, that''s all questions!'), nl, !.
ask_and_count(InCount, OutCount, [Q | Questions]) :-
print(Q),
read_abc(Ans),
increase(Ans, InCount, NewCount),
ask_and_count(NewCount, OutCount, Questions).
read_abc(A) :-
read(A),
member(A, [a,b,c]),
!.
read_abc(A) :-
print('Only a, b and c are accepted! Answer again: '),
read_abc(A).
increase(a, [A, B, C], [X, B, C]) :- X is A + 1.
increase(b, [A, B, C], [A, X, C]) :- X is B + 1.
increase(c, [A, B, C], [A, B, X]) :- X is C + 1.
Sample input and output:
?- ask.
Choose a, b or c: b.
Choose again a, b or c: c.
Think before you choose a, b, or c: c.
Thank you, that's all questions!
You're a(n) c
Maybe I can inspire you to do it another way, which in my opinion is more "prologish" as it relies on lists and leads to simpler code:
question('Choose a, b or c: ').
question('Choose again a, b or c: ').
question('Think before you choose a, b, or c: ').
read_abc(A, Choices) :-
read(A),
member(A, Choices),
!.
read_abc(A, Choices) :-
print('Only '), print(Choices), print(' are accepted! Try again: '),
read_abc(A, Choices).
ask(Answers) :-
findall(Ans, (question(Q), print(Q), read_abc(Ans, [a,b,c])), Answers).
start :-
ask(Answers),
print(Answers).
Sample input and output:
?- start.
Choose a, b or c: c.
Choose again a, b or c: b.
Think before you choose a, b, or c: c.
[c,b,c]
true.
After you have all answers in a list, you can simply count occurences of every answer.
Other way of storing choices is by using assert
and retract
predicates. Expert systems do that. When using assert and retract you can use some predicates like global variables known from other programming languages.