ďťż

Ładny brzuch

unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm)   Edit1: TEdit;   Label1: TLabel;   Button1: TButton;   Label2: TLabel;   procedure Button1Click(Sender: TObject); private   { Private declarations } public   { Public declarations } end; var Form1: TForm1; x : integer; wyswietl, y : string; implementation {$R *.dfm} function silnia(x: integer): integer; begin    if x=1 then result:= 1;    result:= silnia(x-1)*x; end; procedure TForm1.Button1Click(Sender: TObject); begin    wyswietl:=inttostr(silnia(x));    y:=wyswietl;    Label2.Caption:=y; end; end.

powiedzcie mi gdzie jest błąd :blink:
przez ta matematyke to aż zgłupiałem i nawet nie wiem co gdzie mam przypisac w Delphi :blink:
Użytkownik DJ_FireBird edytował ten post 23 listopad 2005, 18:11


function silnia(x: integer): integer; begin   if x=1 then result:= 1 else   result:= silnia(x-1)*x; end; procedure TForm1.Button1Click(Sender: TObject); begin x:=3;   wyswietl:=inttostr(silnia(x));   y:=wyswietl;   Label1.Caption:=y; end;

i nawet wyniku nie wyswietla.. :/ nie wiem co jest grane

function silnia(x: integer): integer; var i: integer; begin Result := 1; for i := 1 to x do Result := Result*i; end;

Update:
Bezpieczniej chyba by było aby wynik funkcji zwracał int64.
Użytkownik Uno edytował ten post 23 listopad 2005, 18:23


unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm)   Edit1: TEdit;   Label1: TLabel;   Button1: TButton;   Label2: TLabel;   procedure Button1Click(Sender: TObject); private   { Private declarations } public   { Public declarations } end; var Form1: TForm1; x, result : integer; wyswietl, y : string; implementation {$R *.dfm} function silnia(x: integer): integer; var i: integer; begin Result := 1; for i := 1 to x do Result := Result*i; end; procedure TForm1.Button1Click(Sender: TObject); begin  wyswietl:=inttostr(silnia(x));  y:=wyswietl;  Label2.Caption:=y; end; end.

i nic :blink: nie wyświetla mi nic w label2 <_<

moze tak... niech tkoś spróbuje dodać sobie edita i buttona i label i po wpisaniu liczby i nacisnięciu na button pojawi sie wynik w labelu za pomoca tej funkjcji bo ja przez ta mate już sie nieziemsko pogubiłem nawet w delphi :unsure:
Użytkownik DJ_FireBird edytował ten post 23 listopad 2005, 18:30
A co za x podałeś ?? Wywal to Result z deklaracji globalnych. Po grzyba te kombinacje ze stringami ?? Przecież wystarczy
x := 10; Label2.Caption := IntToStr(silnia(x));

function silnia(x: integer): integer; var i: integer; begin Result := 1; for i := 1 to x do Result := Result*i; end; procedure TForm1.Button1Click(Sender: TObject); begin  Label2.Caption := IntToStr(silnia(x)); end; end.

dalej nic :unsure:
Użytkownik DJ_FireBird edytował ten post 23 listopad 2005, 18:38
DJ_FireBird - SOA#1. Trzeci raz nie zapytam - jaką wartość podstawiłeś do zmiennej x ??

zadną popatrz wyzej i w cały kod... chce zrobic tak ze po wpisaniu liczby w edit1 i po kliknieciu w button pokaze sie na labelu wynik

zadnej .. nic nie dałem pod x

spróbuj sam całość zrobic bo ja robie kilka razy od początku i nic mi nie wychodzi ... mamo a ja kce w przyszłości pisac programy


zadną popatrz wyzej i w cały kod... chce zrobic tak ze po wpisaniu liczby w edit1 i po kliknieciu w button pokaze sie na labelu wynik

zadnej .. nic nie dałem pod x

spróbuj sam całość zrobic bo ja robie kilka razy od początku i nic mi nie wychodzi ... mamo a ja kce w przyszłości pisac programy

no własnie największy problem jest w tym ze nie wiem jak to przypisać pobraną liczbe zeby pootem została obliczona i wynik pokazany na labelu 2 nie wiem co sie stało ale konkretnie mi sie juz poj***o :/


no własnie największy problem jest w tym ze nie wiem jak to przypisać pobraną liczbe zeby pootem została obliczona i wynik pokazany na labelu 2 nie wiem co sie stało ale konkretnie mi sie juz poj***o :/

unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm)   Edit1: TEdit;   Label1: TLabel;   Button1: TButton;   Label2: TLabel;   procedure Button1Click(Sender: TObject); private   { Private declarations } public   { Public declarations } end; var Form1: TForm1; x : integer; implementation {$R *.dfm} function silnia(x: integer): integer; var i : integer; begin     Result:=1;     for i := 1 to x do     Result := Result*i; end; procedure TForm1.Button1Click(Sender: TObject); begin     x:= strtoint(edit1.Text);     Label2.Caption := IntToStr(silnia(x)); end; end.

i wyskakuje mi błąd : [Error] Unit1.pas(35): Incompatible types: 'String' and 'Integer' poddaje sie
Użytkownik DJ_FireBird edytował ten post 23 listopad 2005, 19:09
Mi taki blad z twoim kodem nie wyskakuje o_O

DJ Firebird: a co masz w Edicie? Bo jeśli jakiś napis, to oczywiście nie spodziewaj się poprawnego działania. Lepiej zastosuj:
x := StrToIntDef(Edit1.Text, 0);

doszedłem sam do tego.. wczoraj chyba dnia na myśle ne nie miałem
kod moze się komuś przydac i jak chcecie mozecie umieścić w FAQ (Delphi)
dodajecie na forme Edit, Label i Button a kod wygląda tak :

unit Unit1; interface uses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  Dialogs, StdCtrls, silnia_f; type  TForm1 = class(TForm)    Edit1: TEdit;    Button1: TButton;    Label1: TLabel;    procedure Button1Click(Sender: TObject);  private    { Private declarations }  public    { Public declarations }  end; var  Form1: TForm1;  wysw : string;  x : integer; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); begin     wysw:=Edit1.Text;     x:=strtoint(wysw);      wysw:=inttostr(silnia(x));     label1.Caption:=wysw; end; end.

poza tym kod do silnia_f :

unit silnia_f; interface function silnia(x: integer): integer; implementation function silnia(x: integer): integer; var i : integer; begin     Result:=1;     for i := 1 to x do     Result := Result*i; end; end.

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • zsf.htw.pl
  •