Last active
August 29, 2015 14:10
-
-
Save yusufsyaifudin/abe1eb284453da4825ba to your computer and use it in GitHub Desktop.
just example program that convert celcius to farenheit and vice versa
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {* Temperature Converter *} | |
| {* Made by Yusuf Syaifudin *} | |
| {* as request from Muhammad Angga Prasetyo - 2 December 2014 *} | |
| program konverter; | |
| { | |
| Formula to convert celsius to farenheit is: | |
| F = ((9/5)* C) +32 | |
| } | |
| function celsiusToFarenheit(celsius: real): real; | |
| var | |
| (* local variable declaration *) | |
| result: real; | |
| begin | |
| result := ((9/5) * celsius) + 32; | |
| // Show 2 place before decimal point and 2 place after decimal point | |
| writeln(celsius:2:2, ' celsius is equal to ', result:2:2, ' farenheit' ); | |
| end; | |
| { | |
| Formula to convert farenheit to celsius is: | |
| C=5/9 (F-32) | |
| } | |
| function farenheitToCelsius(farenheit: real): real; | |
| var | |
| (* local variable declaration *) | |
| result: real; | |
| begin | |
| result := (5/9) * ( farenheit- 32); | |
| // Show 2 place before decimal point and 2 place after decimal point | |
| writeln(farenheit:2:2, ' farenheit is equal to ', result:2:2, ' celsius' ) | |
| end; | |
| // main program | |
| var | |
| a, b : real; | |
| begin | |
| writeln('Welcome to Converter Progam.'); | |
| writeln('=========================================='); | |
| writeln('Select one menu'); | |
| writeln('0. Exit program'); | |
| writeln('1. Celsius to Farenheit'); | |
| writeln('2. Farenheit to Celsius'); | |
| // use READ instead of READLN, because it no more than one input | |
| read(a); | |
| if (a = 0) then | |
| exit | |
| else if (a > 2) then | |
| writeln('Wrong input!') | |
| else | |
| writeln('Input value: '); | |
| read(b); | |
| if (a = 1) then | |
| celsiusToFarenheit(b) | |
| else if (a = 2) then | |
| farenheitToCelsius(b) | |
| else | |
| writeln('No menu you select properly'); | |
| end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment