Contoh Perintah Percabangan If Pada Pemrograman DELPHI

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Contoh Perintah Percabangan IF pada Pemrograman DELPHI

     Berikut merupakan contoh Program Delphi menggunakan perintah Percabangan IF. Ini contoh tampilan program
dan Listing kodenya.

unit TugasPraUTS;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    GroupBox1: TGroupBox;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    ckd: TComboBox;
    Edit2: TEdit;
    ebarang: TEdit;
    eharga: TEdit;
    ebeli: TEdit;
    Label18: TLabel;
    GroupBox2: TGroupBox;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    Label16: TLabel;
    Label17: TLabel;
    etotharga: TEdit;
    eppn: TEdit;
    epotongan: TEdit;
    ebonus: TEdit;
    etotbayar: TEdit;
    ebayar: TEdit;
    ekembali: TEdit;
    cmdulang: TButton;
    cmdhitung: TButton;
    cmdkeluar: TButton;
    procedure bersih;
    procedure ckdClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure cmdhitungClick(Sender: TObject);
    procedure cmdkeluarClick(Sender: TObject);
    procedure ebayarKeyPress(Sender: TObject; var Key: Char);
    procedure cmdulangClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.bersih;
begin
  ckd.text:='';
  ebarang.Text:='';
  eharga.Text:='0';
  ebeli.Text:='';
  etotharga.Text:='0';
  eppn.Text:='0';
  epotongan.Text:='0';
  ebonus.Text:='0';
  etotbayar.Text:='0';
  ebayar.Text:='';
  ekembali.Text:='0';
end;

procedure TForm1.ckdClick(Sender: TObject);


begin
  case strtoint(ckd.Text) of
    1:
    begin
     ebarang.Text:='Mesin Cuci';
     eharga.Text:='2500000';
    end;
    2:
    begin
     ebarang.Text:='Kulkas';
     eharga.Text:='2000000';
    end;
    3:
    begin
     ebarang.Text:='LED TV';
     eharga.Text:='1750000';
    end;
  else
    begin
     ebarang.Text:='DVD Player';
     eharga.Text:='500000';
    end;
  end;

end;

procedure TForm1.FormCreate(Sender: TObject);


begin
 bersih;
ckd.Items.Add('1');
ckd.Items.add('2');
ckd.Items.add('3');
ckd.Items.Add('4');

end;

procedure TForm1.cmdhitungClick(Sender: TObject);


 var total,ppn,pot,totbay:real;
 const pott=0;
begin
  total:= strtoint(eharga.Text) *strtoint(ebeli.Text);
  ppn:= total* 0.1;
  etotharga.Text:=floattostr(total);
  eppn.Text:=floattostr(ppn);

  begin
  if total>=5000000 then
     begin
     pot:= total*0.05;
     epotongan.Text:=floattostr(pot);
     ebonus.Text:='Payung Cantik';
     end
  else
     begin
      pot:=total*0;
      epotongan.Text:=floattostr(pot);
      ebonus.Text:='-';
     end;
  end;
  begin
   totbay:=total+ppn-pot;
   etotbayar.Text:=floattostr(totbay);
  end;

end;

procedure TForm1.cmdkeluarClick(Sender: TObject);


begin
messagedlg('Anda Akan Keluar dari Aplikasi ini!',mtinformation,[mbYes],0);
close;
end;

procedure TForm1.ebayarKeyPress(Sender: TObject; var Key: Char);


 var kembalian:real;
begin
if (key=#13) then
 kembalian:= strtofloat(ebayar.Text)-strtofloat(etotbayar.Text);
 ekembali.Text:=floattostr(kembalian);
end;

procedure TForm1.cmdulangClick(Sender: TObject);


begin
bersih;
end;
end.

You might also like