V
V
Vitaliy Todosiychuk2020-04-03 23:10:44
Lazarus
Vitaliy Todosiychuk, 2020-04-03 23:10:44

Error: Operator is not overloaded: "Real" mod "Real"?

Hello everyone
, I don’t understand why the error unit1.pas (75,13) Error: Operator is not overloaded: "Real" mod "Real"
in programming, I do not
thank you very much in advance

unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls;

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
  private

  public

  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);
var a, b, s: real;
begin
     a := StrToFloat(Edit1.Text);
     b := StrToFloat(Edit2.Text);
     s:= a+b;
     ShowMessage('a+b)= '+FloatTostr(s)+' ' );
end;

procedure TForm1.Button2Click(Sender: TObject);
var a, b, r: real;
begin
     a := StrToFloat(Edit1.Text);
     b := StrToFloat(Edit2.Text);
     r:= a-b;
     ShowMessage('a-b)= '+FloatTostr(r)+' ' );
end;

procedure TForm1.Button3Click(Sender: TObject);
var a, b, d: real;
begin
     a := StrToFloat(Edit1.Text);
     b := StrToFloat(Edit2.Text);
     d:= a/b;
     ShowMessage('a/b)= '+FloatTostr(d)+' ' );
end;

procedure TForm1.Button4Click(Sender: TObject);
var a, b: real; v: double;
begin
     a := StrToFloat(Edit1.Text);
     b := StrToFloat(Edit2.Text);
     v := a mod b; // здесь ошибка
     ShowMessage('a%b)= '+FloatTostr(v)+' ' );
end;

procedure TForm1.Edit1Change(Sender: TObject);
begin

end;

end.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SagePtr, 2020-04-04
@vitaligu

Because the div and mod operators in Pascal are used only for integer division, they do not work with real types

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question