Исправил, но уже после запуска и ввода массива, вылезает ошибка
**Project Project1.exe raised exception class EINvalidOp with message 'Invaid floating point operation'.
Process stopped. Use step or Run to continue.**
Что мне сделать? Завтра нужно ее сдавать.
сейчас задача выглядит так:
Код
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Grids;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
Edit1: TEdit;
Label1: TLabel;
Edit2: TEdit;
Label2: TLabel;
Button1: TButton;
Button2: TButton;
Edit3: TEdit;
Label3: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1; n,m:integer; A:array of array of real;
f:boolean;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
Var i:integer;
begin
f:=true;
n:=StrToInt(Edit1.Text); m:=StrToInt(Edit2.Text);
StringGrid1.ColCount:=m+1;
StringGrid1.RowCount:=n+1;
for i:=1 to n do
StringGrid1.Cells[0,i]:=IntToStr(i);
for i:=1 to m do
StringGrid1.Cells[i,0]:=IntToStr(i);
end;
procedure TForm1.Button2Click(Sender: TObject);
Var i,j:integer; Sum,k:extended; {если к сделать integer, история таже}
begin
if not f then
showmessage('íå ââåëè n,m')
else
begin
SetLength(a,n,m);
k:=0;
Sum:=0;
for i:=0 to n-1 do
for j:=0 to m-1 do
Begin
if StrToInt(StringGrid1.Cells[i, StringGrid1.RowCount-1]) = 1 then
begin
sum := sum + StrToInt(StringGrid1.Cells[i,j]);
k:=k+1;
end;
sum:=sum/k; {после ошибки выделяет эту строчку}
Label1.caption := FloatToStr(sum);
Label2.caption := FloatToStr(k);
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
f:=false;
Edit1.Text:='';
Edit2.Text:='';
Edit3.Text:='';
end;
end.