Forum > General

Help Me

<< < (2/2)

Bart:
I cleaned up a little bit, so the code is easier to read for most of us.


--- Code: ---{File   : PenarikanTunai.pas}
{Desc   : Penarikan Tunai:login,tarik tunai,report penarikan}     //Penarikan=Withdrawal  tunai=cash
program atm;
uses crt;
type
        TClientRec=record
          norek,pin,saldo:longint;        //norek = mink, but probably account number?
        end;
        TClientArray = Array[1..5] of TClientRec;
        TIntegerArray = Array[1..100] of Integer;
var
        //n:TClientRec;        //client
        Clients: TClientArray; //array [1..5] of TClientRec;
        b:TIntegerArray;//array [1..100] of integer;
        d,{i,}Pin,s,Choice,Amount:integer;  //pilihan = selection
        tmp:TClientRec;
        //found:boolean;


procedure data(out TheClients: TClientArray{array of TClientRec});
begin
        TheClients[1].norek:=0001;
        TheClients[1].pin:=1231;
        TheClients[1].saldo:=1000000;
        TheClients[2].norek:=0002;
        TheClients[2].pin:=1232;
        TheClients[2].saldo:=2000000;
        TheClients[3].norek:=0003;
        TheClients[3].pin:=1233;
        TheClients[3].saldo:=3000000;
        TheClients[4].norek:=0004;
        TheClients[4].pin:=1234;
        TheClients[4].saldo:=4000000;
end;

function login(var Clients: TClientArray{array of TClientRec}; x:integer; out AClient: TClientRec): Boolean;
var
        i:integer;
begin
        i:=1;
        Result:=false;
        while ((i<5) and not(Result)) do
        begin
                if Clients[i].pin=x then
                begin
                        Result:=true;
                        AClient:=Clients[i]
                end
                else
                        i:=i+1;
        end;

end;

function saldo(AClient:TClientRec; AValue:integer):integer;
begin
        saldo:=AClient.saldo-AValue;
end;

//I cannot figure out what it is supposed to do
procedure jumlahpenarikan(var a:TIntegerArray{array of integer}); //jumlah penarikan = the number of withdrawals
var
        i,j,tmp:integer;
begin
        for i:=2 to 5 do
        begin
                tmp:=a[i];
                j:=i;
                while ((j>1) and (tmp<a[j-1])) do
                begin
                        a[j]:=a[j-1];
                        j:=j-1;
                end;
                a[j]:=tmp
        end;
end;

begin
        clrscr;
        d:=0;
        writeln('Masukan Pin (Enter Pin)');readln(Pin);   //Masukan = Feedback
        data(Clients);
        if not login(Clients,Pin,tmp) then tmp := Clients[1]; // just for now assume succefull login
        {writeln(Clients[i].saldo);
        readln;}
        {if found=false then
        begin
                for i:=1 to 2 do
                begin
                        writeln('===Masukan Pin===');readln(Pin);
                        data(Clients);
                        login(Clients,Pin,found);
                        tmp:=Clients[i]
                end;
        end;}

        writeln('===Menu===');
        writeln('1.Tarik Tunai (Cash Withdrawal)');   //Tarik Tunai = Cash withdrawal (Pull cash)
        writeln('2.Report Penarikan (Report WithDrawal)');//Report Penarikan = Report Withdrawal
        write('Pilih (Choose): ');
        readln(Choice);

        case Choice of
        1: begin
                write('Masukan Jumlah Penarikan (Enter total withdrawal): ');
                readln(Amount);     //Masukan Jumlah Penarikan=Enter the Total Withdrawal
                if tmp.saldo>=Amount then
                begin
                        if (Amount>2500000) then
                        begin
                          clrscr;
                          gotoxy(15,10);
                          writeln('Penarikan Maksimal adalah 2500000 (Maximum withdrawal is 2500000)');  //Penarikan Maksimal adalah 2500000=Maximum withdrawal is 2500000
                        end
                        else
                        begin
                        //if(tmp.saldo>=Amount) then  //redundant we already know this is true
                                d:=d+1;
                                clrscr;
                                gotoxy(15,10);
                                writeln('Tarik Tunai Berhasil (Pull Cash Successfully)');  //Tarik Tunai Berhasil=Pull Cash Successfully
                                gotoxy(15,11);
                                writeln('Saldo Anda (your balance): ',saldo(tmp,Amount));  //Saldo Anda=your balance (typo: must be salod??)
                                readln;
                                b[d]:=tmp.saldo-Amount;
                        end;
                end
                else
                begin
                        clrscr;
                        gotoxy(15,10);writeln('Error: insuffcient saldo: ',tmp.saldo,', requested amount was: ',Amount);
                        readln;
                end;
             end;
        2: begin
                clrscr;
                jumlahpenarikan(b);
                for s:=1 to d do    //note: at this point d always equals 0, so nothing happens
                begin
                        writeln(b[d]);
                end;
                readln;
           end;
end;

end.

--- End code ---

Notes:

* I gave all variables and types a descriptive name as far as I understand the code
* I added type definition for the array of clients, it is needed for Data procedure, it won't function as intended in the way it was written before
* The login routine now retruns True upon succes, and in that case also returns the found client
* Uncommented the saldo procedure
* If requested amount > 2500000 only don't bother checking if it's > current saldo
* Added some clrscr's and gotoxy()'s
Several issues remain:


* You must handle a failed login
* You can only make 1 withdrawal and the program ends
* It's a mystery to me what the "jumlahpenarikan" procdure is supposed to do
* If you choose "2", nothing happens, see the comments in the code.
* The progrm crashes if user input is invalid (e.g. user enters 'abc' where program expects a number
Hope this helps you a little bit.

Bart

Handoko:
Let me help to translate.

penarikan = withdrawal
tunai = cash
nasabah = client
jumlah penarikan = amount of withdrawal
penarikantunai = cash withdrawal
no_rek = account_number
pin = password
saldo = balance
masukan pin = enter your password
masukan jumlah penarikan = enter the amount of withdrawal
penarikan maksimal adalah = maximum withdrawal amount is
tarik tunai berhasil = cash withdrawal successfully
saldo anda = your balance
pilih = choose

Bart:

--- Quote from: Handoko on April 25, 2016, 06:09:35 pm ---Let me help to translate.

--- End quote ---

Got most of that (see my attempt above).

Bart

Navigation

[0] Message Index

[*] Previous page

Go to full version