Forum > General
Help Me
frozensiswa:
Hi can someone help me with my program, i was trying to make a simple atm program but after login my program error thx for ur help and sorry for my bad english
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{File : PenarikanTunai.pas}{Desc : Penarikan Tunai:login,tarik tunai,report penarikan}program penarikanTunai;uses crt;type nasabah=record norek,pin,saldo:longint; end;var n:nasabah; a:array [1..5] of nasabah; b:array [1..100] of integer; d,i,x,s,pilihan,p:integer; tmp:nasabah; found:boolean; procedure data(var a:array of nasabah);begin a[1].norek:=0001; a[1].pin:=1231; a[1].saldo:=1000000; a[2].norek:=0002; a[2].pin:=1232; a[2].saldo:=2000000; a[3].norek:=0003; a[3].pin:=1233; a[3].saldo:=3000000; a[4].norek:=0004; a[4].pin:=1234; a[4].saldo:=4000000;end; procedure login(var a:array of nasabah;x:integer;found:boolean);var i:integer;begin i:=1; found:=false; while ((i<5) and not(found)) do begin if a[i].pin=x then found:=true else i:=i+1; end; end; {function saldo(s:nasabah;p:integer):integer;begin saldo:=s.saldo-p;end;} procedure jumlahpenarikan(var a:array of integer);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');readln(x); data(a); login(a,x,found); {writeln(a[i].saldo); readln;} {if found=false then begin for i:=1 to 2 do begin writeln('===Masukan Pin===');readln(x); data(a); login(a,x,found); tmp:=a[i] end; end;} writeln('===Menu==='); writeln('1.Tarik Tunai'); writeln('2.Report Penarikan'); write('Pilih;'); readln(pilihan); case pilihan of 1: begin writeln('Masukan Jumlah Penarikan:');readln(p); if tmp.saldo>=p then begin if (p>2500000) then writeln('Penarikan Maksimal adalah 2500000'); if(tmp.saldo>=p) then d:=d+1; clrscr; gotoxy(25,10);writeln('Tarik Tunai Berhasil'); // writeln('Saldo Anda:',saldo(tmp.saldo,p)); readln; b[d]:=tmp.saldo-p; end else clrscr; gotoxy(25,10);writeln('Error'); readln; end; 2: begin clrscr; jumlahpenarikan(b); for s:=1 to d do begin writeln(b[d]); end; readln; end;end;end.
marcov:
Sounds like an array out of bounds access, enable all range and overflow checks.
Add {$R+}{$Q+} after the "program" statement.
Bart:
I don't uderstand the language, so I don't exactly know what it is supposed to do but:
Here are the compiler messages (I saved the project as atm.lpr):
atm.lpr(76,15) Hint: Variable "a" does not seem to be initialized
atm.lpr(77,24) Warning: Variable "found" does not seem to be initialized
atm.lpr(100,20) Warning: Variable "tmp" does not seem to be initialized
atm.lpr(10,9) Note: Local variable "n" not used
atm.lpr(13,11) Note: Local variable "i" not used
In line 100 you do:
--- Code: ---if tmp.saldo>=p then
--- End code ---
This is likely to give you an access violation right from te start.
Fix the compiler warnigs first.
--- Code: ---procedure login(var a:array of nasabah;x:integer;found:boolean);
--- End code ---
I suppose the found parameter is there to indicate wether or not something is found (a pin)?
If so then either declare found as an out parameter (or var, if you must be TurboPascal compatible), or more logical to me: declare it as a function:
--- Code: ---procedure login(var a:array of nasabah;x:integer): Boolean;
--- End code ---
Line 104:
--- Code: ---if(tmp.saldo>=p) then
--- End code ---
This is redundant, you are already in a block that is only executed if (tmp.saldo>=p) (line 100)
Please give your variable names that make sense.
It's perfectly OK to have i, j etc as loop variables but almost anything else would benefit from a more descriptive name.
Bart
Bart:
--- Quote from: marcov on April 25, 2016, 04:07:42 pm ---Sounds like an array out of bounds access, enable all range and overflow checks.
Add {$R+}{$Q+} after the "program" statement.
--- End quote ---
It does not crash here (compiled with all checks enabled), but you're probably right: tmp is not initialized.
B.t.w. the RTE: 4209766, isn't that a bit strange? I was under the impression RTE numbers were byte or word?
Bart
Bart:
--- Quote from: Bart on April 25, 2016, 04:13:49 pm ---I don't uderstand the language, so I don't exactly know what it is supposed to do:
--- End quote ---
Google Traslate:
Penarikan=Withdrawal
tunai=cash
norek = mink, but probably account number?
nasabah=client
jumlah penarikan = the number of withdrawals
Masukan Pin= Feedback Pin (probably: Enter Pin)
Tarik Tunai = Cash withdrawal (Pull cash)
Report Penarikan = Report Withdrawal
Masukan Jumlah Penarikan=Enter the Total Withdrawal
Penarikan Maksimal adalah 2500000=Maximum withdrawal is 2500000
Tarik Tunai Berhasil=Pull Cash Successfully
Saldo Anda=your balance (typo: must be salod?? according to Google Translate)
Pilih=Choose
Bart
Navigation
[0] Message Index
[#] Next page