comp.lang.ada
 help / color / mirror / Atom feed
From: Preben Randhol <randhol+abuse@pvv.org>
Subject: Re: Simple program to find average of 3 numbers
Date: Sat, 5 Jul 2003 10:06:07 +0000 (UTC)
Date: 2003-07-05T10:06:07+00:00	[thread overview]
Message-ID: <slrnbgd8ni.kh.randhol+abuse@kiuk0152.chembio.ntnu.no> (raw)
In-Reply-To: 3F053CD9.135E7340@0.0

Stuart Palin wrote:
> "Robert I. Eachus" wrote:
>> 
>> 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;
>> 
><snip>
>> 
>> 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;
> 
> You might also want to consider what values the intermediate
> calculation Obj_1+Obj_2+Obj_3 can take.  In this instance
> because your type is constrained to a number which should be
> well within the bounds of integer you would not experience a
> problem.

Which instance are you refering to? Mr Eachus' subtype or OP's type
declaration? If you do the calculations above aren't the
intermediate variable of the same type (ONE_TO_100) with same contraint
unless you use a subtype to Integer like Mr Eachus?

-- 
Ada95 is good for you.
http://www.crystalcode.com/codemage/MainMenu/Coding/Ada/IntroducingAda.php



  reply	other threads:[~2003-07-05 10:06 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-07-04  5:01 Simple program to find average of 3 numbers prashna
2003-07-04  5:22 ` John R. Strohm
2003-07-04  5:34   ` Cephus�
2003-07-04  9:54     ` Tarjei T. Jensen
2003-07-05 17:49       ` Cephus�
2003-07-04  5:33 ` Robert I. Eachus
2003-07-04  8:37   ` Stuart Palin
2003-07-05 10:06     ` Preben Randhol [this message]
2003-07-04  5:39 ` tmoran
2003-07-04  9:28   ` prashna
2003-07-04 11:02     ` Stuart Palin
2003-07-04 16:20     ` Pascal Obry
2003-07-05  1:25       ` Robert I. Eachus
     [not found]     ` <1e3ht-ig4.ln1@beastie.ix.netcom.com>
2003-07-04 21:17       ` Jeffrey Creem
2003-07-05  5:07         ` Anders Wirzenius
2003-07-05 14:39 ` Marqmc5
2003-07-06  3:47 ` g_ak
2003-07-08  5:06   ` prashna
2003-07-09 15:25     ` Matthew Heaney
2003-07-09 21:38       ` Robert I. Eachus
2003-07-10 13:52         ` Matthew Heaney
2003-07-10 15:46           ` Robert I. Eachus
2003-07-11  0:56             ` Randy Brukardt
2003-07-11 21:54           ` Robert A Duff
2003-07-11 21:50         ` Robert A Duff
2003-07-11 23:32           ` Robert I. Eachus
2003-07-10  4:55       ` Simon Wright
  -- strict thread matches above, loose matches on Subject: below --
2003-07-09  6:24 christoph.grein
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox