From: Kas_le_chat <kasino@attcanada.net>
Subject: Re: loop and constraint error(Thanks that fix .....)
Date: 1998/10/12
Date: 1998-10-12T00:00:00+00:00 [thread overview]
Message-ID: <36229967.7D78@attcanada.net> (raw)
In-Reply-To: slrn72450c.ork.franke@pax01f.mipool.uni-jena.de
Frank Ecke wrote:
>
> On Sun, 11 Oct 1998 17:13:09 GMT, Kas_le_chat <kasino@attcanada.net> wrote:
>
> > In this projet I have to get a quantity between 0 and 50.From that
> > quantity I have to distribute it in some variables depending on a
> > certain range.When i am out of that fiel 0..50 the program end whit
> > constraint error, but I nead it to loop to the get variable and dont
> > know how to do this.
>
> Try
>
> procedure A is
>
> Quantity : Float range 0.0 .. 50.0;
> package My_Float_IO is new Ada.Text_IO.Float_IO(Float);
> use My_Float_IO;
>
> begin
> Enter_Quantity :
> loop
> begin
> Put("Enter a value between 0.0 and 50.0 ");
> Get(Quantity);
> exit Enter_Quantity;
>
> exception
> when Constraint_Error =>
> Put_Line("I SAID BETWEEN 0.0 AND 50.0");
> when others =>
> Put_Line("Something else went wrong");
> end;
> end loop Enter_Quantity;
> Put(Quantity);
> end A;
>
> Hope this helps.
>
> Frank
>
> --
> Frank Ecke <franke@minet.uni-jena.de>
>
> In a world without walls and fences, who needs windows and gates?
Thanks a lot. That fix the constraint_error and the loop problem.
I still have the data_error problem.When i provoque it, the program go
crazy and loop for ever. Any sugestion is welcome and thanks again.
This is the new code :
With text_io;
use text_io;
procedure pomme is
package es_reels is new Text_IO.Float_IO(Float);
--------d�clation des constantes-----------------------
c_5kg :constant float := 5.0;
c_10kg:constant float := 10.0;
c_20kg:constant float := 20.0;
---------d�claration des variables----------------------
v_pommes : float range 0.0..50.0; --Pour indiquer les bornes de 0 � 50
kg;
v_pomme1 : float; --de o � 5 kg, n�cessaire au calcul du prix;
v_pomme2 : float; --de 05 � 10 kg, n�cessaire au calcul du prix;
V_pomme3 : float; --de 10 � 20 kg, n�cessaire au calcul du prix;
v_pomme4 : float; --de 20 � 50 kg, n�cessaire au calcul du prix;
v_bon_choix : boolean := false;
---------exceptions--------------------------------------
Constraint_Error: exception;
Data_Error : exception;
begin
Entrer_Quantite : --nom de la boucle.
loop
begin
Put("Entrez la quantitee de pomme, MINIMUM 0 et MAXIMUM 50
Kg:");
es_reels.Get(v_pommes);
exit Entrer_Quantite;
exception
when Constraint_Error =>
Put_Line("Un nombre entre 0.0 et 50.0");
when others =>
Put_Line("Un nombre entre 0.0 et 50.0");
end;
end loop Entrer_Quantite;
if ((0.0 < v_pommes) and (v_pommes <= float(5.0))) then v_pomme1 :=
v_pommes; v_pomme2 := 0.0; v_pomme3 := 0.0;v_pomme4 := 0.0;
elsif
((05.0 < v_pommes) and (v_pommes <= 10.0)) then v_pomme2 := v_pommes
- c_5kg;
v_pomme1 := 5.0; v_pomme3 := 0.0; v_pomme4 := 0.0;
elsif
((10.0 < v_pommes) and (v_pommes <= 20.0)) then v_pomme3:= v_pommes
- c_10kg;
v_pomme2 := 5.0; v_pomme1 := 5.0; v_pomme4 := 0.0;
elsif
((20.0 < v_pommes) and (v_pommes <= 50.0)) then v_pomme4 := v_pommes
- c_20kg;
v_pomme3 := 10.0; v_pomme2 := 5.0; V_pomme1 := 5.0;
end if;
--------Sortie--------------------
text_io.put("pomme1= ");
es_reels.put(item=>V_pomme1);
text_io.skip_line;
text_io.put("pomme2= ");
es_reels.put (item=>V_pomme2);
text_io.skip_line;
text_io.put("pomme3= ");
es_reels.put (item =>V_pomme3);
text_io.skip_line;
text_io.put("pomme4= ");
es_reels.put (item =>V_pomme4);
text_io.skip_line;
end pomme;
next prev parent reply other threads:[~1998-10-12 0:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-10-11 0:00 loop and constraint error Kas_le_chat
1998-10-12 0:00 ` Frank Ecke
1998-10-12 0:00 ` Kas_le_chat [this message]
1998-10-13 0:00 ` loop and constraint error(Thanks that fix .....) Matthew Heaney
1998-10-13 0:00 ` loop and constraint error(Thanks that fix ..it all) Kas_le_chat
1998-10-12 0:00 ` loop and constraint error- I really nead help for this problem thanks Kas_le_chat
1998-10-12 0:00 ` alan walkington
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox