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,LOTS_OF_MONEY autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,e07818d50a32cdd7 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-06-03 16:13:44 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!hammer.uoregon.edu!enews.sgi.com!telocity-west!TELOCITY!newsrump.sjc.telocity.net!not-for-mail From: "David C. Hoos, Sr." Newsgroups: comp.lang.ada References: Subject: Re: Constraint error? MIME-Version: 1.0 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 Message-ID: X-Trace: NzggTm9BdXRoVXNlciBURUxPQ0lUWS1SRUFERVJTIDIxNi4yMjcuNDcuNDkgIFN1biwgMDMgSnVu!IDIwMDEgMYY6MTM6MzQgUERU X-Abuse-Info: Please forward ALL headers when reporting abuse. X-Complaints-To: abuse@telocity.net NNTP-Posting-Date: Sun, 03 Jun 2001 16:13:34 PDT Date: Sun, 3 Jun 2001 18:13:40 -0500 Xref: archiver1.google.com comp.lang.ada:8048 Date: 2001-06-03T18:13:40-05:00 List-Id: One obvious error is using the entire string "s" as the argument of the Float'Value attribute function call. You should be using Float'Value (S (1 .. len) Also, there's probably no reason to have the length of "s" so small -- why not make it ten or fifteen characters long, so as to give greater flexibility as to what the user can enter. "McDoobie" wrote in message news:NTyS6.25500$DG1.4223653@news1.rdc1.mi.home.com... > Alright, so I wrote a simple as hell Ada program that figures out the > volume of an object. > > And it worked! I danced around, got all happy, and all the peasants > rejoiced. Or so I thought. > > The program works with some values, but then raises a constraint error > with others. > > Because it's so small, I'll post it up here. > > with Ada.Text_IO, Ada.Float_Text_IO; use Ada.Text_IO, Ada.Float_Text_IO; > > procedure simplevolume is > > Height : Float; Width : Float; Length : Float; > -- The Variables for finding the volume of a shape. > > TotalVolume : Float; > -- The variable that will hold the results. > > s : string(1..5); -- This variable contains 5 chars. Duh! > len : natural; > > begin > > Put_Line( "Enter the Length here: "); > Get_Line( s, len ); > Length := float'value( s ); > New_Line; > Put_Line( "Enter the Width here: "); > Get_Line( s, len ); > Width := float'value( s ); > New_Line; > Put_Line( "Enter the Height here: "); > Get_Line( s, len ); > Height := float'value( s ); > New_Line; > -- It should be obvious what's occurring here. Were collecting the > -- variables of the shape. > > TotalVolume := ((Length * Width) * Height); > > Put_Line( "The total Volume of the shape is: " & TotalVolume'img ); > New_Line; Put_Line( "Goodbye!" ); > > end simplevolume; > > No fancy loops or anything of that nature. Just a straight drop though the > code program. > > Now if I enter like 12.3 for the Length, it works fine, but if I enter > like 5.0, I get a constraint error. > > The specific error I get is... > > raised CONSTRAIN_ERROR : s-valuti.adb:236 > > Now, could someone explain what I'm doing wrong here? I'm a little fuzzy > on constraint errors. > > Thanks. > > McDoobie chris@dont.spam.me > > P.S. Try not to laugh. I'm still a greenhorn okay. ;->