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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,CP1252 X-Google-Thread: 103376,30e0ceaf4e6be70c X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-07-03 22:33:58 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!headwall.stanford.edu!newshub.sdsu.edu!elnk-pas-nf2!newsfeed.earthlink.net!wn14feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi_feed4!attbi.com!sccrnsc01.POSTED!not-for-mail Message-ID: <3F0511BF.6000403@attbi.com> From: "Robert I. Eachus" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2) Gecko/20021120 Netscape/7.01 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Simple program to find average of 3 numbers References: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit NNTP-Posting-Host: 24.62.164.137 X-Complaints-To: abuse@attbi.com X-Trace: sccrnsc01 1057296838 24.62.164.137 (Fri, 04 Jul 2003 05:33:58 GMT) NNTP-Posting-Date: Fri, 04 Jul 2003 05:33:58 GMT Organization: AT&T Broadband Date: Fri, 04 Jul 2003 05:33:58 GMT Xref: archiver1.google.com comp.lang.ada:40043 Date: 2003-07-04T05:33:58+00:00 List-Id: prashna wrote: > Hi friends, > > What is wrong in the following program which is giving constraint > error? > > procedure average is type ONE_TO_100 is range 1 .. 100; > > OBJ1, OBJ2, OBJ3, AVG : ONE_TO_100; begin OBJ1 := 70; OBJ2 := 70; > OBJ3 := 70; AVG := OBJ1+OBJ2+OBJ3/3; end average; I guess the right answer is that nothing is wrong with it, if you want to be sure that you will get Constraint_Error. As written, the code is required to raise Constraint_Error. Oh, and then I could talk about your formatting, and identifier style. But I will address those by example. Try: procedure Average is subtype One_to_100 is Integer range 1 .. 100; Obj_1, Obj_2, Obj_3: One_to_100 := 70; Avg: One_to_100; begin Avg := (Obj_1+Obj_2+Obj_3)/3; -- I assume you really wanted the average, rather than 163. end Average; -- Robert I. Eachus �In an ally, considerations of house, clan, planet, race are insignificant beside two prime questions, which are: 1. Can he shoot? 2. Will he aim at your enemy?� -- from the Laiden novels by Sharon Lee and Steve Miller.