Code:
program EX10DATEVALIDATIONSG(input,output);
uses crt;
const Title:string = ' EX10 DATE VALIDATION ';
By:string = ' By Steve Green ';
var dayNo,monthNo,yearNo:integer;
maxdays:integer;
month:string;
monthnames: array[1..12] of string = ('January','February','March','April',
'May','June','July','August','September','October','November','December');
procedure menu;
begin
ClrScr;
textcolor(red);
writeln(Title);
writeln;
writeln(by);
writeln;
textcolor(green);
writeln;
writeln('Hello, My name is Menu.');
writeln('I am here to make things easier');
writeln('To exit the program press 0');
writeln; //seperate procedure?
writeln;
end;
procedure cont;
begin
writeln;
writeln;
writeln;
textcolor(red);
writeln ('Press <Return> to continue');
readln ();
end;
procedure monthcheck;
begin
case monthNo of {This section gives the}
4,6,9,11: maxdays := 30; {months their correct lengths}
1,3,5,7,8,10,12: maxdays := 31;
2: if yearNo mod 4=0 then maxdays :=29
else maxdays := 28;
end;
end;
procedure daycheck;
begin
case dayNo of
1,21,31: write (dayNo,'st'); // sets prefix for day
2,22: write (dayNo,'nd');
3,23: write (dayNo,'rd');
4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,24,
25,26,27,28,29,30: write(dayNo,'th');
end;
end;
begin {main program}
menu;
write('Please enter the date to continue, enter in this format, 00 00 0000.');
writeln;
readln(dayNo,monthNo,yearNo);
if (dayNo<=0) or (dayNo>31) then
begin
writeln('Sorry, There are only no of days in this month!'); //error handling
writeln('Please enter another day');
readln(dayNo);
end;
if (dayNo>=1) or (dayNo<=31) then
daycheck;
if (monthNo <=0) or (monthNo >12) then
begin
writeln('Sorry, There are only 12 months in a year!');
writeln('Please enter the month again');
read(monthNo);
end;
if (monthNo > 0) and (monthNo <= 12) then
monthcheck;
write(' ',monthnames[monthNo]);
write(' ',yearNo);
writeln;
writeln;
cont;
end.
Bookmarks