AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Code-Bibliothek Neuen Beitrag zur Code-Library hinzufügen Was haut bei dieser Wochentagsberechnung nicht hin?
Thema durchsuchen
Ansicht
Themen-Optionen

Was haut bei dieser Wochentagsberechnung nicht hin?

Ein Thema von Ave · begonnen am 26. Okt 2018 · letzter Beitrag vom 27. Okt 2018
 
Ave

Registriert seit: 26. Okt 2018
1 Beiträge
 
FreePascal / Lazarus
 
#1

Was haut bei dieser Wochentagsberechnung nicht hin?

  Alt 26. Okt 2018, 18:42
Hey,
in der Schule haben wir ein Programm geschrieben, welches ausrechnen sollte, welcher Wochentag an dem angegebenen Datum war/ist/sein wird...
So wie das Programm ist, funktioniert es theoretisch, allerdings hat es irgendwo einen Fehler, welcher dazu führt, dass der Wochentag nicht dem entspricht, welcher er eigentlich sein sollte. Vielleicht findet Ihr ihn ja...
Schon mal, Danke im Voraus!

P.S. Wir arbeiten mit free Pascal, also Lazarus.

Quellcode:

Delphi-Quellcode:
uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);

var a,b1,b2,b3,b4,d,d1,m,i:integer;
c:array [1..12] of integer;

begin
   For i:=1 to 12 do c[i]:=0; // Vorbelegen des Arrays mit 0
   c[1]:=31; // Januar
   c[2]:=c[1]+28; // Februar
   c[3]:=c[2]+31; // ...
   c[4]:=c[3]+30;
   c[5]:=c[4]+31;
   c[6]:=c[5]+30;
   c[7]:=c[6]+31;
   c[8]:=c[7]+31;
   c[9]:=c[8]+30;
   c[10]:=c[9]+31;
   c[11]:=c[10]+30; // November


   a:=strtoint(edit1.Text); // Wochentag des 01.01.
   b1:=5*((a-1) mod 4)+1; // nach: Carl Friedrich Gauss
   b2:=4*((a-1) mod 100);
   b3:=6*((a-1) mod 400);
   b4:= (b1+b2+b3) mod 7;
                                   // ShowMessage (inttostr(b4));
   case b4 of
   0: label3.caption:='Sonntag';
   1: label3.caption:='Montag';
   2: label3.caption:='Dienstag';
   3: label3.caption:='Mittwoch';
   4: label3.caption:='Donnerstag';
   5: label3.caption:='Freitag';
   6: label3.caption:='Samstag';
   end;

   d:=strtoint(edit2.Text); // Tag // Berechnung der Tagesanzahl
   m:=strtoint(edit3.Text); // Monat

   case m of
   1: d1:=d;
   2: d1:=c[1]+d;
   3: d1:=c[2]+d;
   4: d1:=c[3]+d;
   5: d1:=c[4]+d;
   6: d1:=c[5]+d;
   7: d1:=c[6]+d;
   8: d1:=c[7]+d;
   9: d1:=c[8]+d;
   10: d1:=c[9]+d;
   11: d1:=c[10]+d;
   12: d1:=c[11]+d;
   end;
   ShowMessage (inttostr(d1));
   d1:=d1-1; // Minus ein Tag

   d1:= d1 mod 7; // Tag des Datums
   ShowMessage (inttostr(d1));
   If ((a mod 4) = 0) and ((a mod 100) = 0) and ((a mod 400) = 0)
        then d1:=d1+1 ; // ? Schaltjahr


   case d1 of
   0: label6.caption:='Sonntag';
   1: label6.caption:='Montag';
   2: label6.caption:='Dienstag';
   3: label6.caption:='Mittwoch';
   4: label6.caption:='Donnerstag';
   5: label6.caption:='Freitag';
   6: label6.caption:='Samstag';
   end;

end;

end.
Mary

Geändert von Luckie (26. Okt 2018 um 18:55 Uhr) Grund: Code-Tags eingefügt. Bitt beim nächsten mal selber machen. Danke.
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 20:17 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz