Создание простейшего калькулятора (на Delphi) - проблема с вычислительными операциями

Discussion in 'С/С++, C#, Rust, Swift, Go, Java, Perl, Ruby' started by ozhjog, 27 May 2007.

  1. ozhjog

    ozhjog Banned

    Joined:
    28 Apr 2007
    Messages:
    17
    Likes Received:
    10
    Reputations:
    -13
    Прива асем!!!Подскажите пж как сделать так чтоб a+b=sum? заренее спс
     
  2. Joker-jar

    Joker-jar Elder - Старейшина

    Joined:
    11 Mar 2007
    Messages:
    581
    Likes Received:
    205
    Reputations:
    37
    Вопрос непонятный. Поподробней можно?
     
  3. ozhjog

    ozhjog Banned

    Joined:
    28 Apr 2007
    Messages:
    17
    Likes Received:
    10
    Reputations:
    -13
    хочу сделать типа калькулятора ток на сложение вот код:
    unit Unit1;

    interface

    uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, StdCtrls;

    type
    TForm1 = class(TForm)
    CalculateButton: TButton;
    EndEdit: TEdit;
    Label1: TLabel;
    ResultEdit: TEdit;
    Label2: TLabel;
    Edit1: TEdit;
    Label3: TLabel;
    procedure CalculateButtonClick(Sender: TObject);
    private
    { Private declarations }
    public
    { Public declarations }
    end;

    var
    Form1: TForm1;

    implementation

    {$R *.dfm}

    procedure TForm1.CalculateButtonClick(Sender: TObject);
    var
    a:Integer;
    b:Integer;
    sum:Integer;
    EndCount:Integer;

    begin
    if (a=0) and (b=0 ) and (sum=0) then EndCount
    Sum:=a+b;


    ResultEdit.Text:=IntToStr(Sum);
    end;

    end.
     
  4. Zitt

    Zitt Elder - Старейшина

    Joined:
    7 May 2006
    Messages:
    736
    Likes Received:
    268
    Reputations:
    59
    так не проще?
    x,y,c:real;
    x:StrToFloat(Edit1.Text);
    y:StrToFloat(Edit2.text);
    c:x+y;
    Edit3.Text:=FloatToStr(c);
     
  5. ozhjog

    ozhjog Banned

    Joined:
    28 Apr 2007
    Messages:
    17
    Likes Received:
    10
    Reputations:
    -13
    спс я вот так сделал:
    var
    a,b,c:integer ;

    begin
    a:=StrToint(EndEdit.Text);
    b:=strtoint(Edit1.Text);
    c:=a+b;
    ResultEdit.Text:=IntToStr(c);
     
  6. NetMan

    NetMan Elder - Старейшина

    Joined:
    9 Feb 2004
    Messages:
    121
    Likes Received:
    37
    Reputations:
    34
    А можно и без ввода дополнительных переменных! ;)

    Code:
    ResultEdit.Text:=IntToStr( StrToInt(EndEdit.Text) + StrToInt(Edit1.Text) );
    
     
    1 person likes this.
  7. Exile1985

    Exile1985 Elder - Старейшина

    Joined:
    10 Aug 2006
    Messages:
    124
    Likes Received:
    35
    Reputations:
    1
    лучше так, один Edit1

    var
    a,b,c: integer;

    begin
    //при нажатии +
    a:=strtoint(edit1.text);
    edit1.text:=' ';
    // при нажатии =
    b:=strtoint(edit1.text);
    c:=a+b;
    edit1.text:=inttostr(c);
    end;
     
  8. mari00

    mari00 Elder - Старейшина

    Joined:
    27 Oct 2006
    Messages:
    93
    Likes Received:
    40
    Reputations:
    16
    угу так лучше...только можно в кнопках запутаться=\