![]() |
Array Problem, ein kleines Programm - Hilfe
Würden Sie mir bitte mit dem folgenden Programm helfen?
schreiben sie ein programm, das 10 Realwerte von der Tastatur übernimmt und die Anzahl aller Zahlen gleich Null und die Anzahl aller Zahlen im Bereich 3<=x<=5 feststellt und den Mittelwert ermittelt. Ich habe bis jetzt folgendes gemacht:
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
const n=9; type feld=array [0..n] of integer; var A:Feld; var i,anzahl0:integer; var anzahl,m,summe: real; begin writeln('geben sie die Werte ein'); for i:=0 to n do readln (A[i]); writeln('hier sind die werte'); for i:=0 to n do write(A[i]); anzahl:=0; summe:=0; for i:=0 to n do if A[i]<=5 then if A[i]>=3 then anzahl:=anzahl+1; summe:=summe+i; m:=summe/anzahl; writeln('anzahl',anzahl); writeln('summe',summe); writeln('Mittelwert',m); anzahl0:=0; for i:=0 to n do if A[i]=0 then anzahl0:=anzahl0 +1; writeln('anzahl von 0 ist ', anzahl0); end; Dies funktioniert, aber nicht ganz richtig. die Zahlen werden nicht richtig summiert.es kommt immer "10" raus Warum kann ich bei der If-Anweisung folgendes nicht schreiben? : " if A[i]<=5 and A[i]>=3 then...." dabei bekomme ich die Fehlermeldung: "Unkompatible Typen.." wie kann ich dieses Problem lösen!?? Vielem Dank im Voraus! [edit=Admin]Code in Delphi-Tags gesetzt. Mfg, Daniel[/edit] |
Re: Array Problem, ein kleines Programm - Hilfe
Zitat:
Delphi-Quellcode:
Gruß
(A[i]<=5) and (A[i]>=3)
|
Re: Array Problem, ein kleines Programm - Hilfe
Eine Frage vorab: Konsolenanwendung oder Anwendung mit "normalen" Fenstern? Mischen ist zwar möglich, normalerweise aber nicht empfehlenswert
TForm1 weißt auf "normale" Fenster hin, Writeln/Readln auf Konsole ({$APPTYPE CONSOLE}) |
Re: Array Problem, ein kleines Programm - Hilfe
Danke, es weiß ich ,woran es lag.!!!
Zitat:
to Phistev: ist eine Konsolenanwendung! danke für die Tipps :)) |
Re: Array Problem, ein kleines Programm - Hilfe
Hi,
und wie bekommst du einen Button Zitat:
Gruß |
DP-Maintenance
Dieses Thema wurde von "Daniel" von "Programmieren allgemein" nach "Sonstige Fragen zu Delphi" verschoben.
|
Re: Array Problem, ein kleines Programm - Hilfe
ja, unter delphi 3, indem ich einen Button anklicke und auf meiner Schaltfläche plaziere!
Zitat:
|
Re: Array Problem, ein kleines Programm - Hilfe
Zitat:
Sowas hier ist ja möglich, aber auf die Idee muss man erst mal kommen ... :cyclops:
Delphi-Quellcode:
program Project3;
{$APPTYPE CONSOLE} //<-------------- ! uses Forms, Unit3 in 'Unit3.pas' {Form1}; {$R *.res} begin Application.Initialize; Application.CreateForm(TForm1, Form1); Application.Run; end. |
Re: Array Problem, ein kleines Programm - Hilfe
Zitat:
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 04:07 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