Autor Beitrag
uetzenknueff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 19



BeitragVerfasst: Mi 07.03.07 16:59 
Heho


hab eine function geschrieben die aus xkor und ykor den Wert ermitteln soll nur kommt immer der oben genannte Fehler!

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
function berechne_punkte(xkor,ykor:integer):byte;
var d:byte;
    summe:byte;
begin
d:=round(sqrt(sqr(xkor-262.5)+sqr(ykor-262.5))); //262,5 ist der Mittelpkt. einer Dartscheibe und anhand d(M,Auftreffpkt) soll er die Punkte berechnen
case d of
0..12.5: summe:=10;
12.6..25:summe:=9;
25.1..37.5:summe:=8;
37.6..53:summe:=7;
53.1..65.5:summe:=6;
65.6..78:summe:=5;
78.1..90.5:summe:=4;
90.6..103:summe:=3;
103.1..115.5:summe:=2;
115.6..128:summe:=1;
else
summe:=0;
end;
berechne_punkte:=summe;
end;


warum? ist 0..12.5 etwa zu groß???????

hilfe , und danke im voraus

Moderiert von user profile iconGausi: Delphi-Tags hinzugefügt
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mi 07.03.07 17:02 
Hallo und :welcome: in der Entwickler-Ecke!

d ist bei dir als Byte deklariert. Das sind Zahlen zwischen 0 und 255. Und zwar ganze Zahlen.

12.5 ist keine ganze Zahl.

_________________
We are, we were and will not be.


Zuletzt bearbeitet von Gausi am Mi 07.03.07 17:02, insgesamt 1-mal bearbeitet
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mi 07.03.07 17:02 
Byte ist ein Ganzzahlwert zwischen 0 und 255 ... 12.5 ist ein Gleitkomma-Wert ...

Die Datentypen passen nicht zusammen.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
uetzenknueff Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 19



BeitragVerfasst: Mi 07.03.07 19:27 
wenn ich d in real umwandle kommt:
[Fehler] Unit4.pas(51): Ordinaltyp erforderlich!
und immer noch
[Fehler] Unit4.pas(52): Inkompatible Typen: 'Integer' und 'Extended'!


jemand eine Idee?
jakobwenzel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1889
Erhaltene Danke: 1

XP home, ubuntu
BDS 2006 Prof
BeitragVerfasst: Mi 07.03.07 19:28 
Dann machste irgendwas falsch.

Zeig einfach mal Code.

_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.
uetzenknueff Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 19



BeitragVerfasst: Mi 07.03.07 19:32 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
function berechne_punkte(xkor,ykor:integer):byte;
var d:real;
    summe:byte;
begin
d:=round(sqrt(sqr(xkor-262.5)+sqr(ykor-262.5)));
case d of
0..12.5: summe:=10;
12.6..25:summe:=9;
25.1..37.5:summe:=8;
37.6..53:summe:=7;
53.1..65.5:summe:=6;
65.6..78:summe:=5;
78.1..90.5:summe:=4;
90.6..103:summe:=3;
103.1..115.5:summe:=2;
115.6..128:summe:=1;
else
summe:=0;
end;
berechne_punkte:=summe;
end;



so aber egal ob d real oder integer ist es kommt immer Fehler bei real das mit Ordinaltyp und bei integer das mit Inkompatible Typen(was auch bei real zusätzlich noch kommt...)

:shock:

Moderiert von user profile iconChristian S.: Delphi-Tags hinzugefügt
jakobwenzel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1889
Erhaltene Danke: 1

XP home, ubuntu
BDS 2006 Prof
BeitragVerfasst: Mi 07.03.07 19:33 
d ist in diesem Fall immernoch eine Gleitkommazahl. Probiers mal mit dem Ganzzahltyp für d.

_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.
uetzenknueff Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 19



BeitragVerfasst: Mi 07.03.07 19:38 
:?: ich denke dadurch das da Gleitkommazahlen sind muss ich real nehmen?

und wie gesagt bei integer kommt auch eine Fehlermeldung! :cry:
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Mi 07.03.07 19:39 
Hallo,

real ist ein Gleitkomma-Wert, case erfordert einen Ordinaltypen, und das ist real eben nicht.
Die Bedingung 0..12.5 ist auch kein Ordinaltyp.
Mit case geht es nur so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
case {...} of 
0..12  : summe:=10; 
13..25 : summe:=9; 
//...

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mi 07.03.07 19:39 
case erfordert einen ordinal Typen, also einen Integer-Datentyp.
uetzenknueff Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 19



BeitragVerfasst: Mi 07.03.07 20:05 
he danke jetzt funzt es.