mercredi 2 mars 2016

I'm Writing a program that checks a given date for "correctness". Where did I go Wrong?

This is my procedure but I feel like there is just one main problem with my syntax and I can't figure it out.

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;

What am I doing wrong here? I have a lot of error messages but I feel like they >are stemming from one problem.

Aucun commentaire:

Enregistrer un commentaire