RedLion
January 17th, 2007, 20:49
Ok, I'm currently doing my homeworks for our programming teacher(:yawn: ) and I'm working on this old good Pascal(beurk). But I got a problem. Here we go...
Here's a part of my code:
program Date_and_day;
var day,month,year:byte;
kmfevbis,kmfevnbis,kmopair,kmoimp,valdate,ansnonva l:boolean;
answer:char;
begin
(*A loop for going on*)
Repeat
(*Ask user the date*)
writeln('Give the day please');
readln(day);
writeln('Give the month please');
readln(month);
writeln('Give the year please');
readln(year);
(*Initialiazing booleans for the conditions of a good date*)
kmfevbis:=(month=2)and (year mod 4 <> 0)and (1<=day) and (day<=28);
kmfevnbis:=(month=2) and (year mod 4 = 0) and (1<=day) and (day<=29);
kmopair:=(((month=4) or (month=6) or (month=9) or (month=11)) and ((1<=day) and (day<=30)));
kmoimp:=(((month=1) or (month=3) or (month=5) or (month=7) or (month=8) or (month=10) or (month=12)) and ((1<=day) and (day<=31)));
valdate:=(kmfevbis or kmfevnbis or kmopair or kmoimp);
(*Check the validity of the date*)
If not valdate then
repeat writeln('Give a correct date please');
writeln('Give the day please');
readln(day);
writeln('Give the month please');
readln(month);
writeln('Give the year please');
readln(year);
until valdate;
else writeln('The date is correct');
end
So the main issue is when I gave a bad date even if I give a good date after I don't go out of loop "repeat" and it keep asking me to enter a correct date; I can do it old school but i really want to use booleans coz they really clarify the code. Can someone tell me what I'm doing wrong please? many thanks for your help!
Here's a part of my code:
program Date_and_day;
var day,month,year:byte;
kmfevbis,kmfevnbis,kmopair,kmoimp,valdate,ansnonva l:boolean;
answer:char;
begin
(*A loop for going on*)
Repeat
(*Ask user the date*)
writeln('Give the day please');
readln(day);
writeln('Give the month please');
readln(month);
writeln('Give the year please');
readln(year);
(*Initialiazing booleans for the conditions of a good date*)
kmfevbis:=(month=2)and (year mod 4 <> 0)and (1<=day) and (day<=28);
kmfevnbis:=(month=2) and (year mod 4 = 0) and (1<=day) and (day<=29);
kmopair:=(((month=4) or (month=6) or (month=9) or (month=11)) and ((1<=day) and (day<=30)));
kmoimp:=(((month=1) or (month=3) or (month=5) or (month=7) or (month=8) or (month=10) or (month=12)) and ((1<=day) and (day<=31)));
valdate:=(kmfevbis or kmfevnbis or kmopair or kmoimp);
(*Check the validity of the date*)
If not valdate then
repeat writeln('Give a correct date please');
writeln('Give the day please');
readln(day);
writeln('Give the month please');
readln(month);
writeln('Give the year please');
readln(year);
until valdate;
else writeln('The date is correct');
end
So the main issue is when I gave a bad date even if I give a good date after I don't go out of loop "repeat" and it keep asking me to enter a correct date; I can do it old school but i really want to use booleans coz they really clarify the code. Can someone tell me what I'm doing wrong please? many thanks for your help!