comp.lang.ada
 help / color / mirror / Atom feed
From: "McDoobie" <someone@nospam.net>
Subject: Constraint error?
Date: Sun, 03 Jun 2001 22:30:05 GMT
Date: 2001-06-03T22:30:05+00:00	[thread overview]
Message-ID: <NTyS6.25500$DG1.4223653@news1.rdc1.mi.home.com> (raw)

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. ;->



             reply	other threads:[~2001-06-03 22:30 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-06-03 22:30 McDoobie [this message]
2001-06-03 23:13 ` Constraint error? David C. Hoos, Sr.
2001-06-03 23:26   ` McDoobie
2001-06-04 15:42     ` Ted Dennison
2001-06-04 16:12       ` Marin David Condic
2001-06-04 20:52         ` Robert A Duff
2001-06-04 20:50       ` Robert A Duff
2001-06-04 21:13         ` Ted Dennison
2001-06-04 21:44           ` Ehud Lamm
2001-06-05 12:21       ` Marc A. Criley
2001-06-05 15:22         ` Ted Dennison
replies disabled

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