Re: Leap year

[ Related Articles and Replies ] [ DelphiLand Discussion Forum ]

Posted by webmaster Guido on March 12, 2003 at 17:55:19:

In Reply to: Delphi posted by Mike on March 12, 2003 at 14:57:57:

: Hello id like to know how to write a program that prompts for a year in the range 1..9999. then to determine if the year entered is a leap year, if it is then print the message IS LEAP YEAR, if it is not a leap year then print the message NOT LEAP YEAR. Then to repeat asking the user for a year until the number entered is not between 1..9999 Then terminate the program.


You can use Delphi's IsLeapYear function for this (see the Delphi help) :

procedure TForm1.Button1Click(Sender: TObject);
  Year: integer;
  Year := StrToInt(Edit1.Text);
  if (Year < 1) or (Year > 9999) then begin
    ShowMessage('End of the program');
    Close; // program ends when main form is closed
    if IsLeapYear(Year) then
      ShowMessage(Edit1.Text + ' is a leap year')
      ShowMessage(Edit1.Text + ' is not a leap year');

Related Articles and Replies:

[ Related Articles and Replies ]    [ DelphiLand Discussion Forum ]