I am having trouble with this code, are you able to assign a variable to a string or is IS reserved for a comparison or something?
Here is the code, Im just trying to make the internal goal "least" show the least powerful car.
% cars/5.
% cars(BRAND,MANUFACTURER,YEAR,POWER,ENGINE).
cars('Camery','Hiyundi','1980',500,'2l').
cars('Ford XL','Hiyundi','1950',900,'5l').
cars('Tourino','Ford','1920',450,'3l').
cars('Wagon','Ford','1975',1020,'2l').
cars('V8 Super','Mitsibushi','2001',2010,'6l').
% display all cars made by that manufacturer enterd.
made:-
read(MAN),
write('All cars by '),
write(MAN),
!,
nl,
cars(X,MAN,_,_,_),
nl,
write(X),
fail.
% finds the least powerful car.
least:-
write('The least powerful car is '),
Z is 1,
N is 'car',
!,
nl,
cars(X,_,_,P,_),
P > Z, %If power of car is greater then previous car or 1 if this is the first car.
Z is P, %Set Z to P as temporary storage until the next car compares.
N is X, %If above passes, make the N var = to the last car checked.
nl,
fail,
write(N).
Here is the code, Im just trying to make the internal goal "least" show the least powerful car.
% cars/5.
% cars(BRAND,MANUFACTURER,YEAR,POWER,ENGINE).
cars('Camery','Hiyundi','1980',500,'2l').
cars('Ford XL','Hiyundi','1950',900,'5l').
cars('Tourino','Ford','1920',450,'3l').
cars('Wagon','Ford','1975',1020,'2l').
cars('V8 Super','Mitsibushi','2001',2010,'6l').
% display all cars made by that manufacturer enterd.
made:-
read(MAN),
write('All cars by '),
write(MAN),
!,
nl,
cars(X,MAN,_,_,_),
nl,
write(X),
fail.
% finds the least powerful car.
least:-
write('The least powerful car is '),
Z is 1,
N is 'car',
!,
nl,
cars(X,_,_,P,_),
P > Z, %If power of car is greater then previous car or 1 if this is the first car.
Z is P, %Set Z to P as temporary storage until the next car compares.
N is X, %If above passes, make the N var = to the last car checked.
nl,
fail,
write(N).