Created
September 25, 2012 08:27
-
-
Save babab/3780630 to your computer and use it in GitHub Desktop.
My first little Ada program
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
str_date | |
str_date.ali | |
str_date.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
make: str_date.adb | |
gnatmake str_date.adb | |
clean: | |
rm str_date str_date.ali str_date.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with Ada.Integer_Text_IO; | |
with Ada.Text_IO; | |
procedure Str_Date is | |
day : Integer; | |
month: Integer; | |
year : Integer; | |
function GetDayAbbr(n: Integer) return String is | |
begin | |
case n is | |
when 1 | 21 | 31 => return "st"; | |
when 2 | 22 => return "nd"; | |
when 3 | 23 => return "rd"; | |
when 4 .. 20 | 24 .. 30 => return "th"; | |
when others => return "invalid"; | |
end case; | |
end GetDayAbbr; | |
function GetMonthName(n: Integer) return String is | |
begin | |
case n is | |
when 1 => return "January"; | |
when 2 => return "February"; | |
when 3 => return "March"; | |
when 4 => return "April"; | |
when 5 => return "May"; | |
when 6 => return "June"; | |
when 7 => return "July"; | |
when 8 => return "August"; | |
when 9 => return "September"; | |
when 10 => return "October"; | |
when 11 => return "November"; | |
when 12 => return "December"; | |
when others => return ""; | |
end case; | |
end GetMonthName; | |
begin | |
Ada.Text_IO.Put("Enter year [YYYY]: "); | |
Ada.Integer_Text_IO.Get(year); | |
while year < -9999 or else year > 9999 loop | |
Ada.Text_IO.Put_Line("Invalid year, please try again"); | |
Ada.Text_IO.Put("Enter year [YYYY]: "); | |
Ada.Integer_Text_IO.Get(year); | |
end loop; | |
Ada.Text_IO.Put("Enter month [MM]: "); | |
Ada.Integer_Text_IO.Get(month); | |
while month < 1 or else month > 12 loop | |
Ada.Text_IO.Put_Line("Invalid month, please try again"); | |
Ada.Text_IO.Put("Enter month [MM]: "); | |
Ada.Integer_Text_IO.Get(month); | |
end loop; | |
Ada.Text_IO.Put("Enter day [DD]: "); | |
Ada.Integer_Text_IO.Get(day); | |
while day < 1 or else day > 31 loop | |
Ada.Text_IO.Put_Line("Invalid day, please try again"); | |
Ada.Text_IO.Put("Enter day [DD]: "); | |
Ada.Integer_Text_IO.Get(day); | |
end loop; | |
Ada.Text_IO.Put_Line("You entered: "); | |
Ada.Text_IO.Put(GetMonthName(month)); | |
Ada.Text_IO.Put(day'img & GetDayAbbr(day)); | |
Ada.Integer_Text_IO.Put(year, width => 5); | |
Ada.Text_IO.New_Line; | |
end Str_Date; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment