![]() |
Прежде чем задать вопрос, смотрите FAQ.
Рекомендуем загрузить DRKB.
![]() ![]() |
![]() |
Batia |
![]()
Сообщение
#1
|
Гость ![]() |
Нужно нажав на кнопку найти среднее арифметическое
Код procedure TForm1.Button1Click(Sender: TObject); var i, j,k,sum: integer; begin k:=0; sum := 0; with StringGrid1 do begin for i := 0 to ColCount-1 do for j:=0 to RowCount-1 do begin if StrToInt(Cells[i, RowCount-1]) = 1 then begin sum := sum + StrToInt(Cells[i,j]); k:=k+1; end; sum:=sum/k; Label1.caption := IntTostr(sum); Label2.caption := IntToStr(k); end; end; end; Без кнопок програма рабоатет, а так выдает ошибку: **Incompatible type: 'Integer' and 'Extended'** скажите как это исправить |
klem4 |
![]()
Сообщение
#2
|
![]() Perl. Just code it! ![]() ![]() ![]() ![]() ![]() ![]() Группа: Модераторы Сообщений: 4 100 Пол: Мужской Реальное имя: Андрей Репутация: ![]() ![]() ![]() |
поменять sum : integer; на sum : extended;
-------------------- perl -e 'print for (map{chr(hex)}("4861707079204E6577205965617221"=~/(.{2})/g)), "\n";'
|
Batia |
![]()
Сообщение
#3
|
Гость ![]() |
Поменял, но теперь он ругается по поводу этой строки
Код Label1.caption := IntTostr(sum); Пишет: **This is overloaded version of 'IntToStr' that can be called with this arguments** |
volvo |
![]()
Сообщение
#4
|
Гость ![]() |
Попробуй
Label1.caption := FloatTostr(sum); |
Гость |
![]()
Сообщение
#5
|
Гость ![]() |
Исправил, но уже после запуска и ввода массива, вылезает ошибка
**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. |
Batia |
![]()
Сообщение
#6
|
Гость ![]() |
Предыдущие сообщения моё.
|
Batia |
![]()
Сообщение
#7
|
Гость ![]() |
Неужто ничего нельзя сделать?
|
volvo |
![]()
Сообщение
#8
|
Гость ![]() |
Ну, замени ВСЕ IntToStr на FloatToStr... Ты скорее всего вводишь где-то вещественное число, и получаешь то, что получаешь... Перейди полностью на Float ...
Трудно что-то сказать, не зная, какие данные ты вводишь, получается какое-то "гадание на кофейной гуще"... |
![]() ![]() |
![]() |
Текстовая версия | 30.07.2025 23:17 |