Beezle Elite Member
Number of posts : 547 Age : 34 Mood : Points : 253 Registration date : 2008-03-02
Character sheet Weapon: Chakrams Class: Ninja HP: (50/50)
| Subject: Temperature Converter in Prolog Fri Oct 29, 2010 10:13 pm | |
| Provide the user with a menu for converting from celsius to farenheit or farenheit to celsius. The user will then be asked to enter the celcius/farenheit value and the resulting farenheit/celsius value is displayed to them. This predicate should continue to convert as many temperatures as possible until the user gives the option to quit. - Code:
-
% Author: Claudia-Ann Gray % Date: 10/29/2010
temperature:-write('Enter a selection'),nl,write('1 - Celsius to Farenheit'),nl, write('2 - Farenheit to Celsius'),nl,write('3 - Quit'), nl,read(Choice),selection(Choice). selection(Choice):-(Choice=3->nl,write('Thank you'),!);nl,write('Enter a value'), nl,read(Value),(Choice=1->celsius(Value);farenheit(Value)). celsius_to(Value):-Result is (Value*9/5)+32,write('Celsius Value: '),write(Value),nl, write('Farenheit Value: '),write(Result),nl,temperature. farenheit_to(Value):-Result is (Value-32)/9*5,write('Farenheit Value: '),write(Value), nl,write('Celsius Value: '),write(Result),nl,temperature. | |
|