![]() |
Taschenrechner mit Rest (6/5= 1 rest 1)
hallo,
ich bin grad dabei einen taschenrechner zu programmieren. Will einen der auch bin rest rechnet da ich aber / habe muss ich real zahlen nehemn und keine integer zahlen ( also kein div und mod). Und dann habe ich gelesen das man das mir round ab und aufrunden kann aber wo ist hier der fehler ( button6).
Delphi-Quellcode:
unit Unit1;
interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; Button3: TButton; Button4: TButton; Label1: TLabel; Edit1: TEdit; Edit2: TEdit; Button5: TButton; Label2: TLabel; Button6: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button4Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button5Click(Sender: TObject); procedure Button6Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; a,b,c,d: Real; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); begin a:= strtofloat(Edit1.Text); b:= strtofloat(Edit2.Text); c:= a+b; Label1.Caption:=floattostr(c); Form1.color:=random(255*255*255); end; procedure TForm1.Button2Click(Sender: TObject); begin a:= strtofloat(Edit1.Text); b:= strtofloat(Edit2.Text); c:= a-b; Label1.Caption:=floattostr(c); Form1.color:=random(255*255*255); end; procedure TForm1.Button4Click(Sender: TObject); begin a:= strtofloat(Edit1.Text); b:= strtofloat(Edit2.Text); c:= a*b; Label1.Caption:=floattostr(c); Form1.color:=random(255*255*255); end; procedure TForm1.Button3Click(Sender: TObject); begin a:= strtofloat(Edit1.Text); b:= strtofloat(Edit2.Text); If b=0 then begin showmessage('Division durch 0 nicht möglisch'); c:= a/b; Label1.Caption:=floattostr(c); Form1.color:=random(255*255*255); end; end; procedure TForm1.Button5Click(Sender: TObject); var d: Integer; begin randomize; d:=random(4); case d of 0: Button5.Click; 1: Button2.Click; 2: Button3.Click; 3: Button4.Click; end; end; procedure TForm1.Button6Click(Sender: TObject); begin a:=round(strtofloat);//hier wird der Fehler angezeigt b:=round(strtofloat); c:=a div b; Label1.caption:=floattostr(c); d:=a mod b; Label2.Caption:=floattostr(d); end; end. Danke |
AW: Taschenrechner mit Rest (6/5= 1 rest 1)
Delphi-Quellcode:
Guck dir die Zeile noch mal genau an. Und eventuell hilft es auch sich mal die Fehlermeldung genau durchzulesen
a:=round(strtofloat);
|
AW: Taschenrechner mit Rest (6/5= 1 rest 1)
StrToFloat ist genauso wie Round eine Funktion, die bestimmte Parameter verlangt! Der einen übergibst du einen Parameter, der anderen nicht!
|
AW: Taschenrechner mit Rest (6/5= 1 rest 1)
Und gib bitte den Komponenten aussagekräftige Namen. Button1-Button6 sagen NICHTS aus.
Bernhard |
AW: Taschenrechner mit Rest (6/5= 1 rest 1)
Danke aber wie müsste das den dann heißen?
Delphi-Quellcode:
a:=round(strtofloat);
|
AW: Taschenrechner mit Rest (6/5= 1 rest 1)
ach so ich habe da ja vergessen woher der String kommt aber irr-wie zeigt er mir immer noch ne fehlermeldung an:
Delphi-Quellcode:
procedure TForm1.Button6Click(Sender: TObject);
begin a:=round(strtofloat(Edit1.Text)); b:=round(strtofloat(Edit2.Text)); c:=a div b; Label1.caption:=floattostr(c); d:=a mod b; Label2.Caption:=floattostr(d); end; end. |
AW: Taschenrechner mit Rest (6/5= 1 rest 1)
Wie lautet denn die Fehlermeldung?
|
AW: Taschenrechner mit Rest (6/5= 1 rest 1)
Ja, weil a und b Fließkommawerte sind und "div" nur bei Ganzzahlen (Integer) funktioniert.
Dafür einfach die Variablen lokal vom Typ Integer deklarieren! |
AW: Taschenrechner mit Rest (6/5= 1 rest 1)
Also so...
Delphi-Quellcode:
procedure TForm1.Button6Click(Sender: TObject);
var neuA, neuB, neuC, neuD: Integer; begin neuA:=round(strtofloat(Edit1.Text)); neuB:=round(strtofloat(Edit2.Text)); neuC:=neuA div neuB; Label1.caption:=inttostr(neuC); neuD:=neuA mod neuB; Label2.Caption:=inttostr(neuD); end; |
AW: Taschenrechner mit Rest (6/5= 1 rest 1)
aber wenn man das ohne round macht also auch mit integer zaheln geht das nicht warum??
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 01:21 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz