mod和案例不适用于delphi

时间:2018-11-03 18:47:52

标签: delphi switch-statement case mod

我正在尝试在delphi中制作一个计算器,但是我在mod方面遇到了问题,但是我还没有找到解决方法。

procedure TfrmHesapMakinesi.Button1Click(Sender: TObject);
var
sayi1:double;
sayi2:double;
sonuc:double;
islem:byte;
begin
       islem:=(Sender as TButton).Tag;
       sayi1:=strtofloatdef(edtSayi1.Text,0);
       sayi2:=strtofloatdef(edtSayi2.Text,0);
   case islem of
    1:sonuc:=sayi1+sayi2;
    2:sonuc:=sayi1-sayi2;
    3:sonuc:=sayi1*sayi2;
    4:sonuc:=sayi1/sayi2;
    5:sonuc:=sayi1 mod sayi2; //ERROR
  else
    ShowMessage('İşlem seçiniz');
  end;
       lblsonuc.Caption:=floattostr(sonuc);


end;

1 个答案:

答案 0 :(得分:1)

为了将来,请指定您遇到的错误。

但是在这种情况下,很容易理解错误。 mod 运算符仅适用于整数变量,并且您拥有double。您可以编写:

sonuc:= sayi1 - int(sayi1 / sayi2) * sayi2;