From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,4a3d58309fdb60b2 X-Google-Attributes: gid103376,public From: Kas_le_chat Subject: Re: loop and constraint error(Thanks that fix .....) Date: 1998/10/12 Message-ID: <36229967.7D78@attcanada.net>#1/1 X-Deja-AN: 400437030 Content-Transfer-Encoding: 8bit References: <3620E968.526B@attcanada.net> Content-Type: text/plain; charset=iso-8859-1 MIME-Version: 1.0 Reply-To: kasino@attcanada.net NNTP-Posting-Date: Mon, 12 Oct 1998 23:56:12 GMT Newsgroups: comp.lang.ada Date: 1998-10-12T00:00:00+00:00 List-Id: Frank Ecke wrote: > > On Sun, 11 Oct 1998 17:13:09 GMT, Kas_le_chat 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 > > 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;