1.11M Members

Make Validation in Looping

 
0
 

Uses crt;
Const M=5;
Var
A : array [1..M] of Integer;
i,x : Integer;
dapat : boolean;

Function Cek(angka:Integer;batas:Integer):string;
var
Awal:integer;
Begin
For awal:=1 to batas do
Begin
If A[awal]=angka then
Begin
Cek:='Angka Sudah Ada !';
dec(i);
End
Else
Cek:='Angka benar !';
End;
End;

Begin
Clrscr;
Writeln('Pencarian dengan fungsi Logika');
Writeln;

For i:=1 to M do
Begin
Write('Masukkan angka indeks ',i,' : ');Readln(A);
Writeln(Cek(A,i-1));
Writeln;
End;

Write('Angka yang dicari : ');Readln(x);
Writeln;
dapat:=false;
i:=1;

While (i<=M) and (not dapat) do
Begin
If A=x then Dapat:=True
Else
inc(i);
End;

If A=x then
Writeln('Angka ditemukan pada indeks ke-',i,' = ',A)
Else
Writeln('Maaf ! Angka tidak ditemukan');

Readln;
End.

Confuse, Need Help ?

 
0
 

Confused about what ?

 
0
 

Confuse in information condition, in cek function

 
0
 

Try to explain in plain English what you want to add to your code.

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article