1,105,417 Community Members

Make Validation in Looping

Member Avatar
hasbi
Newbie Poster
3 posts since Jan 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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 ?

Member Avatar
pritaeas
mod_pritaeas
11,317 posts since Jul 2006
Reputation Points: 1,420 [?]
Q&As Helped to Solve: 1,835 [?]
Skill Endorsements: 156 [?]
Moderator
Featured
Sponsor
 
0
 

Confused about what ?

Member Avatar
hasbi
Newbie Poster
3 posts since Jan 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Confuse in information condition, in cek function

Member Avatar
pritaeas
mod_pritaeas
11,317 posts since Jul 2006
Reputation Points: 1,420 [?]
Q&As Helped to Solve: 1,835 [?]
Skill Endorsements: 156 [?]
Moderator
Featured
Sponsor
 
0
 

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

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