Programation pascal
Fermé
loujaine221
Messages postés
6
Date d'inscription
mardi 11 août 2009
Statut
Membre
Dernière intervention
12 août 2009
-
12 août 2009 à 15:55
KX Messages postés 16668 Date d'inscription samedi 31 mai 2008 Statut Modérateur Dernière intervention 17 mars 2023 - 12 août 2009 à 17:30
KX Messages postés 16668 Date d'inscription samedi 31 mai 2008 Statut Modérateur Dernière intervention 17 mars 2023 - 12 août 2009 à 17:30
A voir également:
- Programation pascal
- Programation - Forum Programmation
- Comment débuter la programation ✓ - Forum Algorithmes / Méthodes
- Turbo pascal download - Télécharger - Édition & Programmation
- My pascal - Télécharger - Édition & Programmation
- Apprendre programation - Forum Python
2 réponses
KX
Messages postés
16668
Date d'inscription
samedi 31 mai 2008
Statut
Modérateur
Dernière intervention
17 mars 2023
3 005
12 août 2009 à 16:07
12 août 2009 à 16:07
Déjà si ton format d'année est AA, 2003 ne devrait pas être valide.
Ensuite ton problème se résout avec quelques conditions "if" ou "case of"
Ensuite ton problème se résout avec quelques conditions "if" ou "case of"
KX
Messages postés
16668
Date d'inscription
samedi 31 mai 2008
Statut
Modérateur
Dernière intervention
17 mars 2023
3 005
12 août 2009 à 17:30
12 août 2009 à 17:30
Voici une proposition de code, je pense avoir traité tous les cas de saisies incorrectes.
program loujaine221;
function verifDate(s:string):boolean;
var boolJ,boolM,boolA:boolean; intJ,intM,intA,errJ,errM,errA:integer;
begin
if (length(s)=8) and (s[3]='-') and (s[6]='-')
then begin
val(copy(s,1,2),intJ,errJ);
val(copy(s,4,2),intM,errM);
val(copy(s,7,2),intA,errA);
end
else begin
writeln('La date "',s,'" n''est pas correcte');
writeln('La date doit etre sous la forme JJ-MM-AA');
result:=false;
exit;
end;
if (errJ=0) and (errM=0) and (errA=0) // JJ
then begin
boolJ:=(intJ>=1) and (intJ<=31);
boolM:=(intM>=1) and (intM<=12);
boolA:=(intA>=0) and (intA<=99); // toujours vrai puisque errA=0
end
else begin
writeln('La date "',s,'" n''est pas correcte');
writeln('JJ, MM, et AA doivent etre des entiers valides');
result:=false;
exit;
end;
if boolJ and boolM and boolA
then begin
case intM of
1,3,5,7,8,10,12: result:=(intJ<=31); // toujours vrai puisque boolJ
2: result:=(intJ<=29) and ((intA mod 4=0) or (intJ<>29));
4,6,9,11: result:=(intJ<=30);
end;
end
else result:=false;
if result then writeln('La date "',s,'" est correcte')
else begin
writeln('La date "',s,'" n''est pas correcte');
writeln('JJ, MM, et AA ne peuvent pas etre quelconques');
end;
end;
//////////////////////////////////////////////////////////
var date:string;
begin
while true do
begin
write('Entrez une date au format JJ-MM-AA : ');
readln(date);
verifDate(date);
writeln;
end;
end.