这是我的程序,但我觉得我的语法只有一个主要问题,我无法弄清楚。我正在写一个程序,检查给定日期的“正确性”。我哪里做错了?
with Ada.Text_IO;
use Ada.Text_IO;
with Ada.Integer_Text_IO;
use Ada.Integer_Text_IO;
with Ada.Float_Text_IO;
use Ada.Float_Text_IO;
procedure Project_3 is
-------------------------------------------------------------------------
-- Haleigh Graham
-- 02/26/2015
--
--
--
--
--
--
-------------------------------------------------------------------------
type Day_28 is array (1..28) of Natural;
type Day_29 is array (1..29) of Natural;
type Day_30 is array (1..30) of Natural;
type Day_31 is array (1..31) of Natural;
Date_Input : String (1 .. 10);
Month : constant String := Date_Input (1 .. 2);
Day : constant String := Date_Input (4 .. 5);
Year : constant String := Date_Input (7 .. 10);
Valid_Date : Boolean := False;
Valid_Month : Boolean :=False;
type Long_Month is array (1..31) of Natural;
type Short_Month is array (1..30) of Natural;
Index : Positive;
-- Is_February function
function Is_February (Month : in integer) return Boolean is
begin
if Month = 2 then
return True;
else
return False;
end if;
end Is_February;
-- Is_Leap_Year function
function Is_Leap_Year (Year : in integer) return boolean is
begin -- Is_Leap_Year
if Year rem 100 = 0 then
if Year rem 400 = 0 then
return true;
else
return false;
end if;
else
if Year rem 4 = 0 then
return true;
else
return false;
end if;
end if;
end Is_Leap_Year;
-- Is_Valid_Day_31 function
function Is_Valid_Day_31 (Day : in Integer) return Boolean is
begin -- Is_Valid_Day_31
if Day = Day_31 then
return true;
else
return False;
end if;
end Is_Valid_Day_31;
-- Is_Valid_Day_30 function
function Is_Valid_Day_30 (Day : in Integer) return Boolean is
begin -- Is_Valid_Day_30
if Day = Day_30 then
return true;
else
return False;
end if;
end Is_Valid_Day_30;
-- Is_Valid_Day_29 function
function Is_Valid_Day_29 (Day : in Integer) return Boolean is
begin -- Is_Valid_Day_29
if Day = Day_29 then
return true;
else
return False;
end if;
end Is_Valid_Day_29;
-- Is_Valid_Day_28 function
function Is_Valid_Day_28 (Day : in Integer) return Boolean is
begin -- Is_Valid_Day_28
if Day = Day_28 then
return true;
else
return False;
end if;
end Is_Valid_Day_28;
-- Is_Valid_Year function
function Is_Valid_Year (Year : in Integer) return Boolean is
begin -- Is_Valid_Year
if Year > 1700 and Year < 2300 then
return true;
else
return False;
end if;
end Is_Valid_Year;
-- Is_Long_Month function
function Is_Long_Month (Month : in Integer) return Boolean is
begin -- Is_Long_Month function
if Month = Long_Month(Integer) then
return True;
else
return False;
end if;
end Is_Long_Month;
-- Is_Short_Month function
function Is_Short_Month (Month : in Integer) return Boolean is
begin -- Is_Short_Month function
if Month = Short_Month(Integer) then
return True;
else
return False;
end if;
end Is_Short_Month;
-- Main Program
begin
Ada.Text_IO.Put ("Enter the date you wish to check (MM/DD/YYYY): ");
Ada.Integer_Text_IO.Get (Item => Date_Input);
Ada.Text_IO.New_Line;
if Is_Valid_Year = True then
if Is_February = True then
if Is_Leap_Year = True then
if Is_Valid_Day_28 = True then
Valid_Date := True;
else
Valid_Date := False;
end if;
else
if Is_Valid_Day_29 = True then
Valid_Date := True;
else
Valid_Date := False;
end if;
end if;
elsif Is_Long_Month = True then
if Is_Valid_Day_31 = True then
Valid_Date := True;
else
Valid_Date := False;
end if;
elsif Is_Short_Month = True then
if Is_Valid_Day_30 = True then
Valid_Date := True;
else
Valid_Date := False;
end if;
end if;
end if;
end Project_3;
我在做什么错在这里?我有很多错误信息,但我觉得他们是由一个问题引起的。
为什么你会写'Is_Short_Month = True'这样的表达式?它们相当于更易读的'Is_Short_Month'。 –
也许你应该尝试减少你的例子,并一次删除一个问题? –