* loop and constraint error
@ 1998-10-11 0:00 Kas_le_chat
1998-10-12 0:00 ` Frank Ecke
1998-10-12 0:00 ` loop and constraint error- I really nead help for this problem thanks Kas_le_chat
0 siblings, 2 replies; 7+ messages in thread
From: Kas_le_chat @ 1998-10-11 0:00 UTC (permalink / raw)
I am new to ADA and I have a program to do in this langage at school.
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.If you got any answers it will be welcome. Thanks.
This is the code I am working whit:
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;
---------exeptions--------------------------------------
e_exeption: exception;
begin
text_io.put("Entrez la quantitee de pomme, MINIMUM 0 et MAXIMUM 50 Kg:
");
es_reels.get(v_pommes);--Pour obtenir la quantite de pommes
text_io.skip_line;
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;
exception when e_exeption =>
if ((v_pommes < float(0.0)) or (v_pommes >
float(50.0)))then -- condition, la quantite de pomme doit etre plus
grande que 0.0 et plus petite que 50.
text_io.put("La quantit� de pomme n'est pas comprise
entre 0 et 50 kg. ");loop
end loop;
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;
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: loop and constraint error- I really nead help for this problem thanks
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
1998-10-12 0:00 ` alan walkington
1 sibling, 1 reply; 7+ messages in thread
From: Kas_le_chat @ 1998-10-12 0:00 UTC (permalink / raw)
Kas_le_chat wrote:
>
> I am new to ADA and I have a program to do in this langage at school.
> 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.If you got any answers it will be welcome. Thanks.
> This is the code I am working whit:
> 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;
>
> ---------exeptions--------------------------------------
> e_exeption: exception;
>
> begin
>
>
> text_io.put("Entrez la quantitee de pomme, MINIMUM 0 et MAXIMUM 50 Kg:
> ");
> es_reels.get(v_pommes);--Pour obtenir la quantite de pommes
> text_io.skip_line;
>
>
> 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;
>
> exception when e_exeption =>
> if ((v_pommes < float(0.0)) or (v_pommes >
> float(50.0)))then -- condition, la quantite de pomme doit etre plus
> grande que 0.0 et plus petite que 50.
>
> text_io.put("La quantit� de pomme n'est pas comprise
> entre 0 et 50 kg. ");loop
>
>
> end loop;
> 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;
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: loop and constraint error
1998-10-11 0:00 loop and constraint error Kas_le_chat
@ 1998-10-12 0:00 ` Frank Ecke
1998-10-12 0:00 ` loop and constraint error(Thanks that fix .....) Kas_le_chat
1998-10-12 0:00 ` loop and constraint error- I really nead help for this problem thanks Kas_le_chat
1 sibling, 1 reply; 7+ messages in thread
From: Frank Ecke @ 1998-10-12 0:00 UTC (permalink / raw)
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?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: loop and constraint error(Thanks that fix .....)
1998-10-12 0:00 ` Frank Ecke
@ 1998-10-12 0:00 ` Kas_le_chat
1998-10-13 0:00 ` Matthew Heaney
0 siblings, 1 reply; 7+ messages in thread
From: Kas_le_chat @ 1998-10-12 0:00 UTC (permalink / raw)
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;
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: loop and constraint error- I really nead help for this problem thanks
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
0 siblings, 0 replies; 7+ messages in thread
From: alan walkington @ 1998-10-12 0:00 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 4186 bytes --]
> v_pommes : float range 0.0..50.0; --Pour indiquer les bornes de 0
� 50
change to:
> v_pommes : float ;
then
loop
es_reels.get(v_pommes);--Pour obtenir la quantite de pommes
if v_pommes in 0.0 .. 50.0 then
.... do your stuff
else
text_io.put_line("your entry is out of range -- try again");
end if;
end loop;
Alan Walkington
walky@netmagic.net
Kas_le_chat wrote in message <36216FD1.6D9D@attcanada.net>...
>Kas_le_chat wrote:
>>
>> I am new to ADA and I have a program to do in this langage at school.
>> 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.If you got any answers it will be welcome. Thanks.
>> This is the code I am working whit:
>> 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;
>>
>> ---------exeptions--------------------------------------
>> e_exeption: exception;
>>
>> begin
>>
>>
>> text_io.put("Entrez la quantitee de pomme, MINIMUM 0 et
MAXIMUM 50 Kg:
>> ");
>> es_reels.get(v_pommes);--Pour obtenir la quantite de pommes
>> text_io.skip_line;
>>
>>
>> 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;
>>
>> exception when e_exeption =>
>> if ((v_pommes < float(0.0)) or (v_pommes >
>> float(50.0)))then -- condition, la quantite de pomme doit etre plus
>> grande que 0.0 et plus petite que 50.
>>
>> text_io.put("La quantit� de pomme n'est pas comprise
>> entre 0 et 50 kg. ");loop
>>
>>
>> end loop;
>> 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;
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: loop and constraint error(Thanks that fix .....)
1998-10-12 0:00 ` loop and constraint error(Thanks that fix .....) Kas_le_chat
@ 1998-10-13 0:00 ` Matthew Heaney
1998-10-13 0:00 ` loop and constraint error(Thanks that fix ..it all) Kas_le_chat
0 siblings, 1 reply; 7+ messages in thread
From: Matthew Heaney @ 1998-10-13 0:00 UTC (permalink / raw)
Kas_le_chat <kasino@attcanada.net> writes:
> 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.
Do a Skip_Line in the exception handler. This will move past the
current line (which has the bad data).
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: loop and constraint error(Thanks that fix ..it all)
1998-10-13 0:00 ` Matthew Heaney
@ 1998-10-13 0:00 ` Kas_le_chat
0 siblings, 0 replies; 7+ messages in thread
From: Kas_le_chat @ 1998-10-13 0:00 UTC (permalink / raw)
Matthew Heaney wrote:
>
> Kas_le_chat <kasino@attcanada.net> writes:
>
> > 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.
>
> Do a Skip_Line in the exception handler. This will move past the
> current line (which has the bad data).
Thanks a lot it work. This is the code :
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 | data_error =>
Put_Line("Un nombre entre 0.0 et 50.0");
when others =>
text_io.skip_line;
end;
end loop Entrer_Quantite;
Thanks to all who gived me some solutions.
Kas
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~1998-10-13 0:00 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-10-11 0:00 loop and constraint error Kas_le_chat
1998-10-12 0:00 ` Frank Ecke
1998-10-12 0:00 ` loop and constraint error(Thanks that fix .....) Kas_le_chat
1998-10-13 0:00 ` 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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox