First day using Delphi Community IDE, I've been able to create a calculator app. I've done mostly Python and R programming.
But I'm having trouble with the Division Operation. I've hardcoded 2 values just to make sure the operation is based on float numbers.
I would like to get 2.5 in the panel caption, when dividing 5 to 2.
iAns := 5 / 2.0; yields:
[dcc32 Error] hello_world.pas(189): E2010 Incompatible types: 'Integer' and 'Extended'
[dcc32 Error] hello_world.pas(189): E2010 Incompatible types: 'Integer' and 'Extended'
[dcc32 Fatal Error] Project1.dpr(5): F2063 Could not compile used unit 'hello_world.pas'
This is the function that does the operation based on if else conditionals:
procedure TForm1.btnEqualsClick(Sender: TObject);
begin
iNum2 := StrToInt(edt1.Text);
edt1.Clear;
ShowMessage(IntToStr(iNum1));
ShowMessage(IntToStr(iNum2));
if Operant = '+' then
begin
iAns := iNum1 + iNum2;
pnl1.Caption := IntToStr(iAns);
end
else if Operant = '-' then
begin
iAns := iNum1 - iNum2;
pnl1.Caption := IntToStr(iAns);
end
else if Operant = '*' then
begin
iAns := iNum1 * iNum2;
pnl1.Caption := IntToStr(iAns);
end
else if Operant = '/' then
begin
iAns := 5 / 2.0;
pnl1.Caption := FloatToStr(iAns);
end
end;
end.
UPDATE 1:
var
Form1: TForm1;
iNum1, iNum2, iAns : Integer;
rNum1, rNum2, rAns : Integer;
Operant : String;