% problem 5 – Implement get_weather, which first prints a message:
% ‘Enter hot, sun, rain, snow or stop.’ Then it starts a loop,
% in which it prints the prompt and reads the user’s input.
% If the user enters stop the loop ends. Else, if the
% user entered one of the above weather terms, the term is asserted
% (stored in prolog’s memory). Else if the user entered something
% else, an error message is displayed and the loop continues.

:- dynamic cold/0.
:- dynamic hot/0.
:- dynamic sun/0.
:- dynamic rain/0.
:- dynamic snow/0.

printer:-write(‘Weather :’),read(Reply),process(Reply),nl.
get_weather:-write(‘Enter hot, sun, rain,snow or stop’),nl,printer.
process(stop):-!.
process(hot):-assert(hot),printer.
process(sun):-assert(sun),printer.
process(rain):-assert(rain),printer.
process(snow):-assert(snow),printer.
process(Message):-write(Message),write(‘ is an invalid input’),nl,get_weather.

Leave a Reply

Your email address will not be published. Required fields are marked *

Name *