richie3366

caisse ada 1

Sep 27th, 2012
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ada 3.18 KB | None | 0 0
  1. with Entrees_Sorties; use Entrees_Sorties;
  2. with Ada.Strings; use Ada.Strings;
  3. with Ada.Strings.Fixed; use Ada.Strings.Fixed;
  4.  
  5. procedure caisse is
  6.   aRendre : Float;
  7.   pieces : array (0..7) of Float := (0.01, 0.02, 0.05, 0.10, 0.20, 0.50, 1.00, 2.00);
  8.   billets : array (0..6) of Float := (5.00, 10.00, 20.00, 50.00, 100.00, 200.00, 500.00);
  9.  
  10.   nbPieces : array (0..7) of Integer := (40, 40, 40, 60, 30, 40, 20, 15);
  11.   nbBillets : array (0..6) of Integer := (10, 10, 10, 6, 5, 5, 1);
  12.  
  13.   nbMem : Float;
  14. begin
  15.  
  16.   put("Stock de la caisse :");
  17.   new_line;
  18.  
  19.   for i in 0..6 loop
  20.       if(nbBillets(i)>1) then
  21.          put(Integer'Image(nbBillets(i)) & " billets de " & Trim(Integer'Image(Integer(billets(i))), Left));
  22.       else
  23.          put(Integer'Image(nbBillets(i)) & " billet de " & Trim(Integer'Image(Integer(billets(i))), Left));
  24.       end if;
  25.       new_line;
  26.    end loop;
  27.  
  28.   for i in 0..7 loop
  29.       if(nbPieces(i)>1) then
  30.          put(Integer'Image(nbPieces(i)) & " piece de ");
  31.       else
  32.          put(Integer'Image(nbPieces(i)) & " piece de ");
  33.       end if;
  34.      
  35.       if(pieces(i) < 1.0) then
  36.           put("0.");
  37.         if(pieces(i) < 0.10) then
  38.                   put("0" & Trim(Integer'Image(Integer(pieces(i)*100.0)), Left));
  39.         else
  40.            put(Trim(Integer'Image(Integer(pieces(i)*100.0)), Left));
  41.         end if;
  42.       else
  43.         put(Trim(Integer'Image(Integer(pieces(i))), Left));
  44.        
  45.       end if;
  46.      
  47.       new_line;
  48.    end loop;
  49.  
  50.   new_line;
  51.   put("Monnaie a rendre ?   ");
  52.   get(aRendre);
  53.  
  54.   --put(aRendre);
  55.  
  56.   for i in 0..6 loop
  57.     if(aRendre >= billets(6-i)) then
  58.       nbMem := Float((Integer(aRendre*100.0) - (Integer(aRendre*100.0) mod Integer(billets(6-i)*100.0)))/Integer(billets(6-i)*100.0));
  59.       new_line;
  60.  
  61.       if(Integer(nbMem) > nbBillets(6-i)) then
  62.          nbMem := Float(nbBillets(6-i));
  63.       end if;
  64.  
  65.       put(Integer'Image(Integer(nbMem)));
  66.      
  67.       if(Integer(nbMem) > 1) then
  68.          put(" billets de ");
  69.       else
  70.          put(" billet de ");
  71.       end if;
  72.  
  73.      
  74.       put(Trim(Integer'Image(Integer(billets(6-i))), Left));
  75.  
  76.       aRendre := (Float(Integer(aRendre*100.0) - Integer(billets(6-i)*100.0)*Integer(nbMem))/100.0);
  77.     end if;
  78.   end loop;
  79.  
  80.   for i in 0..7 loop
  81.     if(aRendre >= pieces(7-i)) then
  82.       nbMem := Float((Integer(aRendre*100.0) - (Integer(aRendre*100.0) mod Integer(pieces(7-i)*100.0)))/Integer(pieces(7-i)*100.0));
  83.       new_line;
  84.      
  85.       if(Integer(nbMem) > nbPieces(7-i)) then
  86.          nbMem := Float(nbPieces(7-i));  
  87.       end if;
  88.      
  89.       put(Integer'Image(Integer(nbMem)));
  90.  
  91.       if(Integer(nbMem) > 1) then
  92.          put(" pieces de ");
  93.       else
  94.          put(" piece de ");
  95.       end if;
  96.  
  97.      
  98.       if(pieces(7-i) < 1.0) then
  99.         put("0.");
  100.         if(pieces(7-i) < 0.10) then
  101.                   put("0" & Trim(Integer'Image(Integer(pieces(7-i)*100.0)), Left));
  102.         else
  103.            put(Trim(Integer'Image(Integer(pieces(7-i)*100.0)), Left));
  104.         end if;
  105.       else
  106.         put(Trim(Integer'Image(Integer(pieces(7-i))), Left));
  107.        
  108.       end if;
  109.      
  110.  
  111.       aRendre := (Float(Integer(aRendre*100.0) - Integer(pieces(7-i)*100.0)*Integer(nbMem))/100.0);
  112.     end if;
  113.   end loop;
  114.  
  115.  
  116.  
  117. end caisse;
Advertisement
Add Comment
Please, Sign In to add comment