Autor Beitrag
GericasS
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 540

Windows Vista Home Premium
D2010, VisualStudio2008
BeitragVerfasst: Do 05.07.07 22:25 
Hey,

ich hab jetzt angefangen mit dem Crashkurs von Christian und Delphi 7 !
Bin jetzt bei der Aufgabe mit dem Taschenrechner ähnlichen Programm.
Ich hab schon die Funktionen für Plus und Minus geschrieben, gab auch keine Probleme.
Dann habe ich versucht das ganze zu erweitern, mit geteilt und multiplizieren.

Das sah dann so aus

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
procedure TForm1.Button2Click(Sender: TObject);
var zahl1, zahl2, quotient : Integer;
begin
  zahl1 := StrToInt(edit1.Text);
  zahl2 := StrToInt(edit2.Text);
  quotient := zahl1/zahl2;
  label1.caption := IntToStr(quotient);
end;

procedure TForm1.Button3Click(Sender: TObject);
var zahl1, zahl2, produkt : Integer;
begin
  zahl1 := StrToInt(edit1.text);
  zahl2 := StrToInt(edit2.text);
  produkt := zahl1*zahl2;
  label1.caption := IntToStr(produkt)
end;

end.


Den unteren Teil mit dem Produkt etc. macht keine Probleme nur in den Zeilen des quotienten kommt eine Fehlermeldung !

Inkompatible Typen 'Integer' und 'Extended'

Was mach ich da falsch ?

PS : Hoffe ich hah diesmal das richtige Forum getroffen !

Grüße GericasS :D

Moderiert von user profile iconGausi: Code- durch Delphi-Tags ersetzt
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: Do 05.07.07 22:31 
Real,FloatToStr

_________________
Blackheart666
Der Irrsinn ist bei Einzelnen etwas Seltenes, - aber bei Gruppen, Parteien, Völkern, Zeiten die Regel. (Friedrich Nietzsche)
GericasS Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 540

Windows Vista Home Premium
D2010, VisualStudio2008
BeitragVerfasst: Do 05.07.07 22:37 
Ich danke dir für deine schnelle Hilfe nur leider kann ich nicht viel mit anfangen,
wenn ich das einfach ersetzte wird das auch nichts. Das Real für die Kommazahlen genutzt wird weiß ich, aber wofür dieses "FloatToStr" ? Könntest du das in meinem Quellcode vll. mal ersetzten, damit ich sehe wie es geht ?
Agawain
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 460

win xp
D5, MySQL, devxpress
BeitragVerfasst: Do 05.07.07 22:41 
Du kannst für einen Taschenrechnerfunktion nicht, oder nur für ganz spezielle Funktionen mit Integer arbeiten.

Jedenfalls kommen bei einer Division oft gebrochene Zahlen raus.
Dafür der Datentyp real, double...schau Dir die Bereichsgrenzen der Datentypen an und entscheide, welche benöigt.

Noch ein Tipp...eine Division durch 0 schickt Dein Programm ins Nirgendwo, also besser abfangen.

Gruß

Aga
Agawain
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 460

win xp
D5, MySQL, devxpress
BeitragVerfasst: Do 05.07.07 22:46 
Also weißte, gibt ja sowas wie ne Hilfedatei in Delphi, die sollte man schon mal gelegentlich in Anspruch nehmen.

FloaToStr wandelt ein Fließkommazahl in einen String um, ist als das Analogon zu IntToStr.

Gruß

Aga
GericasS Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 540

Windows Vista Home Premium
D2010, VisualStudio2008
BeitragVerfasst: Do 05.07.07 22:47 
okay,

danke erstmal für die weitere schnelle Hilfe ich werde mal schauen was sich noch so machen lässt !