Hello I have to create a memo program using Memo,Label,Edit,Button.It has to show up on the memo and it has to be number between:(x>40) and (x<=120)
procedure TForm1.Button1Click(Sender: TObject);
var n,i,x:integer;
begin
n:=StrToInt(Edit1.Text);
for i:=1 to n do
if i mod (40=40) and (120=120) then Memo1.lines.add(IntToStr(i));
end;
end.
Any help appreciated!
That code doesn't make sense and won't even compile (did you try?).
In the first place the syntax for
mod is:
number MOD number and it returns an integer: "i mod (40=40) ..." is a very obvious syntax error.
In the second place, why are you even using
mod?
MOD is the complement to
div; it returns the remainder of an integer division. But, as you said, all you need is to know whether "(x >40) and (x <= 120)" so, what's wrong with this code then?
procedure TForm1.Button1Click(Sender: TObject);
var
n, i {, x never used!}: integer;
begin
n:=StrToInt(Edit1.Text);
if n <= 40 then Exit; { No point to follow further!!! }
for i:=1 to n do
if (i > 40) and (i <= 120) then
Memo1.lines.add(IntToStr(i));
end;
Do note that this is (almost) a mere restatement of your code. It can be made quicker and more robust.The "
if n < 40 ..." is just an example to get you going.