program konversi suhu (procedure)

Saya mencoba membuat program konversi suhu menggunakan procedure.
Didalam program ini terdapat percabangan case of else dan perulangan repeat until. Coba pahami kegunaannya.

Program Konversi_Suhu;
Uses WinCrt;

var f,c,r : real;
     a,ul  : char;
procedure farein_celcius;
begin
   Writeln('Program Konversi Fareinheit Ke Celcius');
   Writeln('======================================');
   Writeln;
   Write('Masukan Suhu dalam Farenheit: ');readln(f);
   c:=5/9*(f-32);
   Writeln;
   Writeln('Jadi Suhu Dalam Celcius Adalah: ',c:4:2);
end;

procedure farein_reamur;
begin
   Writeln('Program Konversi Fareinheit Ke Reamur');
   Writeln('=====================================');
   Writeln;
   Write('Masukan Suhu dalam Farenheit: ');readln(f);
   r:=4/9*(f-32);
   Writeln;
   Writeln('Jadi Suhu Dalam Reamur Adalah: ',r:4:2);
end;

procedure celcius_farein;
begin
   Writeln('Program Konversi Celcius Ke Fareinheit');
   Writeln('======================================');
   Writeln;
   Write('Masukan Suhu dalam Celcius: ');readln(c);
   f:=(9/5)*c+32;
   Writeln;
   Writeln('Jadi Suhu Dalam Fareinheit Adalah: ',f:4:2);
end;

procedure celcius_reamur;
begin
   Writeln('Program Konversi Celcius ke Reamur');
   Writeln('==================================');
   Writeln;
   Write('Masukan Suhu dalam Celcius: ');readln(c);
   r:=(4/5)*c;
   Writeln;
   Writeln('Jadi Suhu Dalam Reamur Adalah: ',r:4:2);
end;

procedure reamur_celcius;
begin
   writeln('Program Konversi Reamur ke Celcius');
   Writeln('==================================');
   Writeln;
   Write('Masukan Suhu dalam Reamur: ');readln(r);
   c:=(5/4)*r;
   Writeln;
   Writeln('Jadi Suhu Dalam Celcius Adalah: ',c:4:2);
end;

procedure reamur_farein;
begin
   writeln('Program Konversi Reamur ke Fareinheit');
   Writeln('=====================================');
   Writeln;
   Write('Masukan Suhu dalam Reamur: ');readln(r);
   f:= (9/4)*r+32;
   Writeln;
   Writeln('Jadi Suhu Dalam Fareinheit Adalah: ',f:4:2);
end;

begin
  repeat
  clrscr;
    writeln ('Program konversi suhu');
    writeln;
    writeln ('1. fareinheit - celcius');
    writeln ('2. fareinheit - reamur');
    writeln ('3. celcius -  reamur');
    writeln ('4. celcius - fareinheit');
    writeln ('5. reamur - celcius');
    writeln ('6. reamur - farenheit');
    writeln;

    write ('pilih nomor konversi : '); read (a);
    writeln;
 
case a of
   '1' : farein_celcius;
   '2' : farein_reamur;
   '3' : celcius_reamur;
   '4' : celcius_farein;
   '5' : reamur_celcius;
   '6' : reamur_farein;
else
   writeln ('Nomor yang anda masukkan salah');
end;

   Writeln;Writeln;
   Write('Mau Coba Lagi [Y/T]: ');Readln(ul);
  Until Upcase(ul)'Y';
End.

Lagi

Iklan