Hi everybody
I write program with prolog programming language that represent the following rules :
Rule 1 : if the day is Monday or the day is Tuesday or the day isWednesday
or the day is Thursday or the day is Friday then today is a workday.
Rule 2 : if the day is Saturday or the day is Sunday then today is the
weekend.
Rule 3 : if today is workday and the time is ‘between 9 am and 5 pm’ then
operation is ‘during business hours’.
Rule 4 : if today is workday and the time is ‘before 9 am’ then operation
is ‘not during business hours’.
Rule 5 : if today is workday and the time is ‘after 5 pm’ then operation is
‘not during business hours’.
Rule 6 : if today is weekend then operation is ‘not during business hours’.
Rule 7 : if the month is January or the month is February or the month is
December then the season is summer.
Rule 8 : if the month is March or the month is April or the month is May
then the season is autumn.
Rule 9 : if the month is June or the month is July or the month is August
then the season is winter.
Rule 10 : if the month is September or the month is October or the month
is November then the season is spring.
Rule 11 : if the season is spring and operation is ‘during business hours’ then
thermostat setting is ’20 degrees’.
but I have an error (each time I get the same result '15 degrees' ) to solve this problem I add startagain rule but the problem still exists,could anyone help me please
this is the program
member(H,[H|T]).
member(X,[H|T]):-member(X,T).
testday(Y):-member(Y,[saturday,sunday]),assert(today(weekend)).
testday(Y):-member(Y,[monday,tuesday,wednesday,thursday,friday]),assert(today(workday)).
testtime(Z):-member(Z,['between 9 am and 5 pm']),today(workday),assert(operation('during business hours')).
testtime(Z):-member(Z,['after 5 pm','before 9 am']),today(workday),assert(operation('not during business hours')).
testtime(Z):-today(weekend),assert(operation('not during business hours')).
testmonth(X):-member(X,[january,febrauary,december]),assert(season(summer)).
testmonth(X):-member(X,[march,april,may]),assert(season(autumn)).
testmonth(X):-member(X,[june,july,august]),assert(season(winter)).
testmonth(X):-member(X,[septemeber,october,december]),assert(season(spring)).
thermostat_setting('15 degrees'):-
season(spring),
operation('not during business hours').
thermostat_setting('20 degrees'):-
season(spring),
operation('during business hours').
thermostat_setting('24 degrees'):-
season(summer),
operation('during business hours').
thermostat_setting('27 degrees'):-
season(summer),
operation('not during business hours').
thermostat_setting('20 degrees'):-
season(autumn),
operation('during business hours').
thermostat_setting('16 degrees'):-
season(autumn),
operation('not during business hours').
thermostat_setting('18 degrees'):-
season(winter),
operation('during business hours').
thermostat_setting('14 degrees'):-
season(winter),
operation('not during business hours').
go:-write('what month is it?'),nl,read(X),testmonth(X),nl,
write('what day is it?'),nl,read(Y),testday(Y),nl,
write('what time is it?'),nl,read(Z),testtime(Z),nl,
thermostat_setting(TH),write(TH).
startagain:-retract(today(X)),retract(operation(X)),retract(season(X)).
I write program with prolog programming language that represent the following rules :
Rule 1 : if the day is Monday or the day is Tuesday or the day isWednesday
or the day is Thursday or the day is Friday then today is a workday.
Rule 2 : if the day is Saturday or the day is Sunday then today is the
weekend.
Rule 3 : if today is workday and the time is ‘between 9 am and 5 pm’ then
operation is ‘during business hours’.
Rule 4 : if today is workday and the time is ‘before 9 am’ then operation
is ‘not during business hours’.
Rule 5 : if today is workday and the time is ‘after 5 pm’ then operation is
‘not during business hours’.
Rule 6 : if today is weekend then operation is ‘not during business hours’.
Rule 7 : if the month is January or the month is February or the month is
December then the season is summer.
Rule 8 : if the month is March or the month is April or the month is May
then the season is autumn.
Rule 9 : if the month is June or the month is July or the month is August
then the season is winter.
Rule 10 : if the month is September or the month is October or the month
is November then the season is spring.
Rule 11 : if the season is spring and operation is ‘during business hours’ then
thermostat setting is ’20 degrees’.
but I have an error (each time I get the same result '15 degrees' ) to solve this problem I add startagain rule but the problem still exists,could anyone help me please
this is the program
member(H,[H|T]).
member(X,[H|T]):-member(X,T).
testday(Y):-member(Y,[saturday,sunday]),assert(today(weekend)).
testday(Y):-member(Y,[monday,tuesday,wednesday,thursday,friday]),assert(today(workday)).
testtime(Z):-member(Z,['between 9 am and 5 pm']),today(workday),assert(operation('during business hours')).
testtime(Z):-member(Z,['after 5 pm','before 9 am']),today(workday),assert(operation('not during business hours')).
testtime(Z):-today(weekend),assert(operation('not during business hours')).
testmonth(X):-member(X,[january,febrauary,december]),assert(season(summer)).
testmonth(X):-member(X,[march,april,may]),assert(season(autumn)).
testmonth(X):-member(X,[june,july,august]),assert(season(winter)).
testmonth(X):-member(X,[septemeber,october,december]),assert(season(spring)).
thermostat_setting('15 degrees'):-
season(spring),
operation('not during business hours').
thermostat_setting('20 degrees'):-
season(spring),
operation('during business hours').
thermostat_setting('24 degrees'):-
season(summer),
operation('during business hours').
thermostat_setting('27 degrees'):-
season(summer),
operation('not during business hours').
thermostat_setting('20 degrees'):-
season(autumn),
operation('during business hours').
thermostat_setting('16 degrees'):-
season(autumn),
operation('not during business hours').
thermostat_setting('18 degrees'):-
season(winter),
operation('during business hours').
thermostat_setting('14 degrees'):-
season(winter),
operation('not during business hours').
go:-write('what month is it?'),nl,read(X),testmonth(X),nl,
write('what day is it?'),nl,read(Y),testday(Y),nl,
write('what time is it?'),nl,read(Z),testtime(Z),nl,
thermostat_setting(TH),write(TH).
startagain:-retract(today(X)),retract(operation(X)),retract(season(X)).