I have an issue that makes me crazy!!! I want to calculate the grades average of some students by their id. I wrote the code below, but it stacks after the first calculation :
list_sum([], 0).
list_sum([Head | Tail], TotalSum) :-
list_sum(Tail, Sum1),TotalSum is Head + Sum1.
find_student_avg(Student,Year,Avg):-
findall(X, grades(_,student(id(Student),_,_,_,_,_),year(Year),normal(X)), L),
%% not(resit_grades(_,student(id(Student),_,_,_,_,_),_,_)),
list_sum(L,Sum),
length(L,N), N>0,
Avg is Sum / N.
find_all_avgs([Head|Tail],Year,L):-
find_student_avg(Head,Year,Avg),append(L1,[Head|Avg],L),find_all_avgs(Tail,Year,L2).
I need my result to be something like L=[[id1|avg1],[id2|avg2],[id3|avg3]]. Can somenone help?????
Pleaseeeee!!!!
Any idea on how to sort this list by avg?