user1261259
user1261259

Reputation: 1

Using multiple clauses - Prolog

I have a prolog program that contains details on course modules, students, and the modules they are attending. The program is as follows:

module(42, mod_details('Vocal Skills', 'Dawn Upshaw')).
module(53, mod_details('Physics', 'Dave Jones')).
module(64, mod_details('Maths', 'John Richards')).
module(75, mod_details('History', 'El Capitan')).

student('Bruce Wayne', student_det('100', '2')).
student('Clarke Kent', student_det('200', '3')).
student('Scott Summers', student_det('300', '1')).
student('Richard Kimble', student_det('400', '2')).

attends(100, 42).
attends(300, 42).
attends(400, 42).
attends(200, 53).
attends(300, 53).
attends(300, 64).
attends(100, 75).
attends(200, 75).
attends(300, 75).
attends(400, 75).

print_studentnos_for_modno(ModNo):-
        attends(SNo, ModNo),
    write(SNo).

print_studentnos_for_modtitle(ModTitle):-
    module(ModNo, mod_details(ModTitle, Lect)),
    attends(SNo, ModNo),
    write(SNo).

is_a_student(StudentName):-
    student(StudentName, student_det(SNo, Year)).

print_students_lectured_by(Lect):-
    module(ModNo, mod_details(ModTitle, Lect)),
    attends(SNo, ModNo),
    student(StudentName, student_det(SNo, Year)),   
    write(StudentName), write(' '),
    write(SNo).

The last clause, print_students_lectured_by(Lect), is supposed to print out the names of the students followed by their student number. However, it only gives a false answer.

I am extremely new at this so would appreciate any advice on how to amend my clause.

Many Thanks Andy

Upvotes: 0

Views: 205

Answers (1)

Chetter Hummin
Chetter Hummin

Reputation: 6837

student('Bruce Wayne', student_det('100', '2')) 

should be

student('Bruce Wayne', student_det(100, 2))

and similarly for the rest of the students.

NOTE: Haven't tried this out myself

Upvotes: 2

Related Questions