Code:
program EX10DATEVALIDATIONSG(input,output);
uses crt;
const Title:string = ' EX10 DATE VALIDATION ';
By:string = ' By Steve Green ';
var dayNo,monthNo,yearNo:integer; //the intitial input by the user
monthnumber,maxdays:integer;
month,day:string;
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?
end;
procedure cont;
begin
writeln;
writeln;
writeln;
textcolor(red);
writeln ('Press <Return> to continue');
readln ();
end;
procedure monthcheck;
begin case monthnumber of //use an array instead? {Naming of Months}
1: month :=('January ');
2: month :=('Febuary ');
3: month :=('March ');
4: month :=('April ');
5: month :=('May ');
6: month :=('June ');
7: month :=('July ');
8: month :=('August ');
9: month :=('September ');
10:month :=('October ');
11:month :=('November ');
12:month :=('December ');
end;
case monthnumber 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;
writeln;
write('Please enter the date to continue, enter in this format, 00 00 0000 and press <enter> to continue.');
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');
read(dayNo);
end;
if (dayNo>=1) or (dayNo<=31) then //should have month / day count check first?
//if day no is satifies run proc daycheck (for prefix)
daycheck;
if (monthNo <=0) or (monthNo >12) then
begin //error handling for months
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(month); // *^&?ì$(*^&?ì(*&(GAH!!!!!!!!!!!!!!!!!
write(' ',yearNo);
writeln;
writeln
// cont;
end.
I did have a working version that would display date etc using an array of month names and that was working, I then started changing things and lost the original save. Maybe I'm going about this wrong by using case instead of arrays? Any input / help would be hugely appreciated.
Bookmarks