Hi!
I think that Zoran is right.
But one step back:
I hate stupid and lazy teachers.
What about negativ numbers?
What about the range of the number?
Is the poor boy forced to insert something between −2.147.483.648 and 2.147.483.647 into the two edit fields?
And the information about "inclusive" - let's be kind - is unsharp.
To make a version that is maybe OK for school let's do two things:
Reduce the range to 0..255 - also known as a byte.
This makes the question about negative numbers obsolete.
And let's assume that the "inclusive" is used the way like Zoran thinks it is right.
Then - Mister Teacher - it goes that way:
.....
var D : array[1..10] of byte;
K1,K2 : byte;
procedure TForm1.FormCreate(Sender: TObject);
var i : integer;
begin
for i := 1 to 10 do D[i] := random (256);
end;
procedure TForm1.Button1Click(Sender: TObject);
var err1, err2, hits,i : integer;
begin
val(Edit1.text, K1, err1);
val (Edit2.Text,K2, err2);
if err1 <> 0 then begin showMessage ('Error in Edit1'); exit; end;
if err2 <> 0 then begin showMessage ('Error in Edit2'); exit; end;
hits := 0;
for i := 1 to 10 do
begin
if (K1 <= D[i]) and (K2>= D[i]) then inc (hits);
end;
ShowMessage ( IntToStr(hits)+ ' Elements between '+IntToStr(K1)+' and '+IntToStr(K2) );
end;
And finally:
Teaching the teacher - it's an impossible job.
Winni
PS.:
God knows everything. Teachers know everything better.