Extraction d'information d'un numéro INSEE.

Un programme qui vous demande votre numero
INSEE et donne divers informations.

with Ada.Text_Io, Ada.Integer_Text_IO, Ada.Characters.Handling, Ada.Calendar;

procedure Numeroinsee is
   use Ada.Text_Io, Ada.Characters.Handling ;
   Encore : Character;

   procedure NumeroAnnex is

      use Ada.Text_Io, Ada.Characters.Handling, Ada.Integer_Text_IO, Ada.Calendar ;
      Numero : String(1..14);
      Longueur : Natural;
      Bon : Boolean;
      Annee : Natural;

   begin
      New_Line;
      Put("Bonjour nous sommes en ");
      Put(Year(Clock),4);
      New_Line;
      Put_Line("Entrer votre numéro de sécurité sociale ( ou numéro INSEE ) : ") ;
      Get_Line(Numero,Longueur);
      New_Line;

      if Longueur /= 13 then
         Put_Line("Vous devez entrer 13 charactères !!");
      elsif (Numero(1)/='1' and Numero(1)/='2') then
         Put_Line("Vous devez avoir un 1 ou un 2 sur le premier caractère");
         Bon := False;
      else
         Bon := True;
      end if;

      if Bon=True then
         for I in 1..Longueur loop
            if Is_Digit(Numero(I))/=true then
               Put_Line("Un des caractères du numero n'est pas un chiffre!!");
               Bon := False;
            else
               Bon := True;
            end if;
         end loop;
      end if;

      if Bon=True then
         case Numero(1) is
            when '1' =>
               Put("Vous êtes né en ");
               Annee := 1900+Integer'Value(Numero(2..3));
               Put(Annee,4);
               New_Line;
               Put("Vous avez donc ");
               Annee := Year(Clock)-Annee;
               Put(Annee,2); -- Pas centenaire
               Put_Line(" ans");
            when '2' =>
               Put("Vous êtes née en ");
               Annee := 1900+Integer'Value(Numero(2..3));
               Put(Annee,4);
               New_Line;
                Put("Vous avez donc ");
               Annee := Year(Clock)-Annee;
               Put(Annee,2); -- Pas centenaire
               Put_Line(" ans");
            when others =>
               Put_Line("Une erreur a echapée !!");
         end case;
      end if;
   end NumeroAnnex;

begin
   Encore := 'O';
   Recommence:
   while (Encore='O' or Encore='o') loop
      NumeroAnnex;
      Put_Line("Entrer un autre numéro INSEE ?");
      Get(Encore);
      Skip_Line;
   end loop Recommence;
   Put_Line("Au revoir !");
end numeroinsee ;