Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Program KonversiSuhu;
- uses wincrt;
- var InpSuhu:real; {C=Celcius, R=Reamur, F=Fahrenheit, K=Kelvin}
- OutC, OutR, OutF, OutK:real;
- JenisSuhu:char;
- InpSuhuString:string; {var penampung input suhu dalam string}
- tempSuhu:real; {var sementara untuk konver string ke real}
- ErrCode:integer; {var untuk menampung error saat konversi string ke real}
- label 100,200;
- {program utama}
- begin
- {menu}
- 100: {label 100}
- write('Masukan jenis suhu C/R/F/K : ');
- readln(JenisSuhu);
- JenisSuhu:=upcase(JenisSuhu); {mengubah jenis suhu ke upper case}
- if (JenisSuhu <> 'C') then
- if (JenisSuhu <> 'R' ) then
- if (JenisSuhu <> 'F' ) then
- if (JenisSuhu <> 'K' ) then
- begin
- writeln ('Jenis suhu salah, silahkan ulangi!');
- writeln;
- goto 100;
- end;
- 200: {label 200}
- write('Masukan besar suhu : ');
- readln(InpSuhuString);
- val(InpSuhuString,inpSuhu,ErrCode);
- if ErrCode <> 0 then
- begin
- writeln('Data suhu yang dimasukan tidak valid, masukan data numerik!');
- writeln;
- goto 200;
- end;
- writeln;
- { hitung konversi suhu}
- writeln('Hasil Konversi Suhu, Untuk Suhu ', inpSuhu:6:2,' ',JenisSuhu);
- writeln('--------------------------------------');
- if (JenisSuhu = 'C') then {jika input suhu dalam celcius}
- begin
- OutR:=InpSuhu * 4/5;
- OutF:=(InpSuhu *9/5) + 32;
- OutK:=InpSuhu + 273;
- writeln('Suhu dalam Reamur = ', OutR:6:2);
- writeln('Suhu dalam Fahrenheit = ', OutF:6:2);
- writeln('Suhu dalam Kelvin = ', OutK:6:2);
- end
- else if (JenisSuhu = 'R') then {jika input suhu dalam reamur}
- begin
- OutC:=InpSuhu * 5/4;
- OutF:=(InpSuhu * 9/4) + 32;
- OutK:=(InpSuhu * 5/4) + 273;
- writeln('Suhu dalam Celcius = ', OutC:6:2);
- writeln('Suhu dalam Fahrenheit = ', OutF:6:2);
- writeln('Suhu dalam Kelvin = ', OutK:6:2);
- end
- else if (JenisSuhu = 'F') then {jika input suhu dalam fahrenheit}
- begin
- OutC:=InpSuhu * 5/9;
- OutR:=(InpSuhu * 4/9) + 32;
- OutK:=(InpSuhu * 5/9) + 273;
- writeln('Suhu dalam Celcius = ', OutC:6:2);
- writeln('Suhu dalam Reamur = ', OutR:6:2);
- writeln('Suhu dalam Kelvin = ', OutK:6:2);
- end
- else if (JenisSuhu = 'K') then {jika input suhu dalam kelvin}
- begin
- OutC:=InpSuhu - 273;
- OutR:=(InpSuhu - 273) * 4/5;
- OutF:=((InpSuhu - 273) * 9/5) + 32;
- writeln('Suhu dalam Celcius = ', OutC:6:2);
- writeln('Suhu dalam Reamur = ', OutR:6:2);
- writeln('Suhu dalam Fahrenheit = ', OutF:6:2);
- end;
- readln;
- end. {end program}
Advertisement
Add Comment
Please, Sign In to add comment